Modify model tests

This commit is contained in:
jiangjiajun
2022-11-05 07:54:16 +00:00
parent f00212aa42
commit cf8f53e36d
7 changed files with 111 additions and 92 deletions

View File

@@ -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)