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_matting_ppmatting():
model_url = "https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz"
input_url = "https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg"
fd.download_and_decompress(model_url, ".")
fd.download(input_url, ".")
model_path = "./PP-Matting-512"
fd.download_and_decompress(model_url, "resources")
fd.download(input_url, "resources")
model_path = "./resources/PP-Matting-512"
model_file = os.path.join(model_path, "model.pdmodel")
params_file = os.path.join(model_path, "model.pdiparams")
config_file = os.path.join(model_path, "deploy.yaml")
@@ -32,26 +32,27 @@ def test_matting_ppmatting():
model_file, params_file, config_file, runtime_option=rc.test_option)
# 预测图片抠图结果
im = cv2.imread("./matting_input.jpg")
result = model.predict(im.copy())
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/ppmatting_result.pkl"
if pkl_url:
fd.download(pkl_url, ".")
with open("./ppmatting_result.pkl", "rb") as f:
baseline = pickle.load(f)
diff = np.fabs(np.array(result.alpha) - np.array(baseline))
thres = 1e-05
assert diff.max() < thres, "The diff is %f, which is bigger than %f" % (
diff.max(), thres)
im = cv2.imread("./resources/matting_input.jpg")
for i in range(2):
result = model.predict(im)
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/ppmatting_result.pkl"
if pkl_url:
fd.download(pkl_url, "resources")
with open("./resources/ppmatting_result.pkl", "rb") as f:
baseline = pickle.load(f)
diff = np.fabs(np.array(result.alpha) - np.array(baseline))
thres = 1e-05
assert diff.max() < thres, "The diff is %f, which is bigger than %f" % (
diff.max(), thres)
def test_matting_ppmodnet():
model_url = "https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz"
input_url = "https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg"
fd.download_and_decompress(model_url, ".")
fd.download(input_url, ".")
model_path = "./PPModnet_MobileNetV2"
fd.download_and_decompress(model_url, "resources")
fd.download(input_url, "resources")
model_path = "./resources/PPModnet_MobileNetV2"
model_file = os.path.join(model_path, "model.pdmodel")
params_file = os.path.join(model_path, "model.pdiparams")
config_file = os.path.join(model_path, "deploy.yaml")
@@ -59,27 +60,29 @@ def test_matting_ppmodnet():
model_file, params_file, config_file, runtime_option=rc.test_option)
# 预测图片抠图结果
im = cv2.imread("./matting_input.jpg")
result = model.predict(im.copy())
im = cv2.imread("./resources/matting_input.jpg")
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/ppmodnet_result.pkl"
if pkl_url:
fd.download(pkl_url, ".")
with open("./ppmodnet_result.pkl", "rb") as f:
baseline = pickle.load(f)
diff = np.fabs(np.array(result.alpha) - np.array(baseline))
thres = 1e-05
assert diff.max() < thres, "The diff is %f, which is bigger than %f" % (
diff.max(), thres)
for i in range(2):
result = model.predict(im)
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/ppmodnet_result.pkl"
if pkl_url:
fd.download(pkl_url, "resources")
with open("./resources/ppmodnet_result.pkl", "rb") as f:
baseline = pickle.load(f)
diff = np.fabs(np.array(result.alpha) - np.array(baseline))
thres = 1e-05
assert diff.max() < thres, "The diff is %f, which is bigger than %f" % (
diff.max(), thres)
def test_matting_pphumanmatting():
model_url = "https://bj.bcebos.com/paddlehub/fastdeploy/PPHumanMatting.tgz"
input_url = "https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg"
fd.download_and_decompress(model_url, ".")
fd.download(input_url, ".")
model_path = "./PPHumanMatting"
fd.download_and_decompress(model_url, "resources")
fd.download(input_url, "resources")
model_path = "./resources/PPHumanMatting"
# 配置runtime加载模型
runtime_option = fd.RuntimeOption()
model_file = os.path.join(model_path, "model.pdmodel")
@@ -89,17 +92,18 @@ def test_matting_pphumanmatting():
model_file, params_file, config_file, runtime_option=rc.test_option)
# 预测图片抠图结果
im = cv2.imread("./matting_input.jpg")
result = model.predict(im.copy())
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/pphumanmatting_result.pkl"
if pkl_url:
fd.download(pkl_url, ".")
with open("./pphumanmatting_result.pkl", "rb") as f:
baseline = pickle.load(f)
diff = np.fabs(np.array(result.alpha) - np.array(baseline))
thres = 1e-05
assert diff.max() < thres, "The diff is %f, which is bigger than %f" % (
diff.max(), thres)
im = cv2.imread("./resources/matting_input.jpg")
for i in range(2):
result = model.predict(im)
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/pphumanmatting_result.pkl"
if pkl_url:
fd.download(pkl_url, "resources")
with open("./resources/pphumanmatting_result.pkl", "rb") as f:
baseline = pickle.load(f)
diff = np.fabs(np.array(result.alpha) - np.array(baseline))
thres = 1e-05
assert diff.max() < thres, "The diff is %f, which is bigger than %f" % (
diff.max(), thres)