mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 17:17:14 +08:00
Modify model tests
This commit is contained in:
@@ -22,9 +22,9 @@ import runtime_config as rc
|
||||
def test_classification_yolov5cls():
|
||||
model_url = "https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n-cls.tgz"
|
||||
input_url = "https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg"
|
||||
fd.download_and_decompress(model_url, ".")
|
||||
fd.download(input_url, ".")
|
||||
model_path = "yolov5n-cls/yolov5n-cls.onnx"
|
||||
fd.download_and_decompress(model_url, "resources")
|
||||
fd.download(input_url, "resources")
|
||||
model_path = "resources/yolov5n-cls/yolov5n-cls.onnx"
|
||||
# use ORT
|
||||
runtime_option = fd.RuntimeOption()
|
||||
runtime_option.use_ort_backend()
|
||||
@@ -32,18 +32,19 @@ def test_classification_yolov5cls():
|
||||
model_path, runtime_option=rc.test_option)
|
||||
|
||||
# compare diff
|
||||
im = cv2.imread("./ILSVRC2012_val_00000010.jpeg")
|
||||
result = model.predict(im.copy(), topk=5)
|
||||
with open("yolov5n-cls/result.pkl", "rb") as f:
|
||||
expect = pickle.load(f)
|
||||
|
||||
diff_label = np.fabs(
|
||||
np.array(result.label_ids) - np.array(expect["labels"]))
|
||||
diff_score = np.fabs(np.array(result.scores) - np.array(expect["scores"]))
|
||||
thres = 1e-05
|
||||
assert diff_label.max(
|
||||
) < thres, "The label diff is %f, which is bigger than %f" % (
|
||||
diff_label.max(), thres)
|
||||
assert diff_score.max(
|
||||
) < thres, "The score diff is %f, which is bigger than %f" % (
|
||||
diff_score.max(), thres)
|
||||
im = cv2.imread("./resources/ILSVRC2012_val_00000010.jpeg")
|
||||
for i in range(2):
|
||||
result = model.predict(im, topk=5)
|
||||
with open("resources/yolov5n-cls/result.pkl", "rb") as f:
|
||||
expect = pickle.load(f)
|
||||
|
||||
diff_label = np.fabs(
|
||||
np.array(result.label_ids) - np.array(expect["labels"]))
|
||||
diff_score = np.fabs(np.array(result.scores) - np.array(expect["scores"]))
|
||||
thres = 1e-05
|
||||
assert diff_label.max(
|
||||
) < thres, "The label diff is %f, which is bigger than %f" % (
|
||||
diff_label.max(), thres)
|
||||
assert diff_score.max(
|
||||
) < thres, "The score diff is %f, which is bigger than %f" % (
|
||||
diff_score.max(), thres)
|
||||
|
Reference in New Issue
Block a user