[Other] Update example codes using download_model api (#486)

* update example codes using download_model api

* add resource files to repo

* add resource files to repo

* fix

* reduce unused lib

* fix
This commit is contained in:
chenjian
2022-11-11 13:35:12 +08:00
committed by GitHub
parent b0a30a7b10
commit 0d0389f8d9
6 changed files with 63 additions and 12 deletions

View File

@@ -1,7 +1,9 @@
import fastdeploy as fd
import cv2
import os
import fastdeploy as fd
import fastdeploy.utils
def parse_arguments():
import argparse
@@ -9,10 +11,10 @@ def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_dir",
required=True,
default=None,
help="Path of PaddleDetection model directory")
parser.add_argument(
"--image", required=True, help="Path of test image file.")
"--image", default=None, help="Path of test image file.")
parser.add_argument(
"--device",
type=str,
@@ -39,9 +41,14 @@ def build_option(args):
args = parse_arguments()
model_file = os.path.join(args.model_dir, "model.pdmodel")
params_file = os.path.join(args.model_dir, "model.pdiparams")
config_file = os.path.join(args.model_dir, "infer_cfg.yml")
if args.model_dir is None:
model_dir = fd.download_model(name='ppyoloe_crn_l_300e_coco')
else:
model_dir = args.model_dir
model_file = os.path.join(model_dir, "model.pdmodel")
params_file = os.path.join(model_dir, "model.pdiparams")
config_file = os.path.join(model_dir, "infer_cfg.yml")
# 配置runtime加载模型
runtime_option = build_option(args)
@@ -49,7 +56,11 @@ model = fd.vision.detection.PPYOLOE(
model_file, params_file, config_file, runtime_option=runtime_option)
# 预测图片检测结果
im = cv2.imread(args.image)
if args.image is None:
image = fd.utils.get_detection_test_image()
else:
image = args.image
im = cv2.imread(image)
result = model.predict(im.copy())
print(result)