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

update detection example
This commit is contained in:
jm12138
2022-11-18 13:19:13 +08:00
committed by GitHub
parent 143506b654
commit 3848196829
15 changed files with 181 additions and 69 deletions

View File

@@ -7,9 +7,9 @@ def parse_arguments():
import ast
parser = argparse.ArgumentParser()
parser.add_argument(
"--model", required=True, help="Path of nanodet_plus onnx model.")
"--model", default=None, help="Path of nanodet_plus onnx model.")
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,
@@ -37,13 +37,21 @@ def build_option(args):
args = parse_arguments()
if args.model is None:
model = fd.download_model(name='NanoDetPlus_320')
else:
model = args.model
# 配置runtime加载模型
runtime_option = build_option(args)
model = fd.vision.detection.NanoDetPlus(
args.model, runtime_option=runtime_option)
model = fd.vision.detection.NanoDetPlus(model, 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)

View File

@@ -9,10 +9,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,
@@ -41,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='faster_rcnn_r50_vd_fpn_2x_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)
@@ -51,7 +56,11 @@ model = fd.vision.detection.FasterRCNN(
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)

View File

@@ -9,10 +9,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,
@@ -48,9 +48,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='mask_rcnn_r50_1x_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)
@@ -58,7 +63,11 @@ model = fd.vision.detection.MaskRCNN(
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)

View File

@@ -9,10 +9,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 +39,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='picodet_l_320_coco_lcnet')
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 +54,11 @@ model = fd.vision.detection.PicoDet(
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)

View File

@@ -9,10 +9,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,
@@ -41,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='ppyolo_r50vd_dcn_1x_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)
@@ -51,7 +56,11 @@ model = fd.vision.detection.PPYOLO(
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)

View File

@@ -2,7 +2,6 @@ import cv2
import os
import fastdeploy as fd
import fastdeploy.utils
def parse_arguments():

View File

@@ -9,10 +9,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 +39,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='yolov3_darknet53_270e_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 +54,11 @@ model = fd.vision.detection.YOLOv3(
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)

View File

@@ -9,10 +9,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 +39,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='yolox_s_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 +54,11 @@ model = fd.vision.detection.PaddleYOLOX(
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)

View File

@@ -7,9 +7,9 @@ def parse_arguments():
import ast
parser = argparse.ArgumentParser()
parser.add_argument(
"--model", required=True, help="Path of scaledyolov4 onnx model.")
"--model", default=None, help="Path of scaledyolov4 onnx model.")
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,
@@ -37,13 +37,21 @@ def build_option(args):
args = parse_arguments()
if args.model is None:
model = fd.download_model(name='ScaledYOLOv4-P5')
else:
model = args.model
# 配置runtime加载模型
runtime_option = build_option(args)
model = fd.vision.detection.ScaledYOLOv4(
args.model, runtime_option=runtime_option)
model = fd.vision.detection.ScaledYOLOv4(model, 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)

View File

@@ -1,7 +1,6 @@
import cv2
import fastdeploy as fd
import fastdeploy.utils
def parse_arguments():

View File

@@ -7,9 +7,9 @@ def parse_arguments():
import ast
parser = argparse.ArgumentParser()
parser.add_argument(
"--model", required=True, help="Path of yolov5 onnx model.")
"--model", default=None, help="Path of yolov5 onnx model.")
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,
@@ -37,12 +37,21 @@ def build_option(args):
args = parse_arguments()
if args.model is None:
model = fd.download_model(name='YOLOv5s')
else:
model = args.model
# 配置runtime加载模型
runtime_option = build_option(args)
model = fd.vision.detection.YOLOv5(args.model, runtime_option=runtime_option)
model = fd.vision.detection.YOLOv5(model, 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)

View File

@@ -7,9 +7,9 @@ def parse_arguments():
import ast
parser = argparse.ArgumentParser()
parser.add_argument(
"--model", required=True, help="Path of yolov5lite onnx model.")
"--model", default=None, help="Path of yolov5lite onnx model.")
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,
@@ -37,13 +37,21 @@ def build_option(args):
args = parse_arguments()
if args.model is None:
model = fd.download_model(name='YOLOv5Lite-s')
else:
model = args.model
# 配置runtime加载模型
runtime_option = build_option(args)
model = fd.vision.detection.YOLOv5Lite(
args.model, runtime_option=runtime_option)
model = fd.vision.detection.YOLOv5Lite(model, 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)

View File

@@ -7,9 +7,9 @@ def parse_arguments():
import ast
parser = argparse.ArgumentParser()
parser.add_argument(
"--model", required=True, help="Path of yolov6 onnx model.")
"--model", default=None, help="Path of yolov6 onnx model.")
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,
@@ -37,12 +37,21 @@ def build_option(args):
args = parse_arguments()
if args.model is None:
model = fd.download_model(name='YOLOv6s')
else:
model = args.model
# 配置runtime加载模型
runtime_option = build_option(args)
model = fd.vision.detection.YOLOv6(args.model, runtime_option=runtime_option)
model = fd.vision.detection.YOLOv6(model, 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)

View File

@@ -7,9 +7,9 @@ def parse_arguments():
import ast
parser = argparse.ArgumentParser()
parser.add_argument(
"--model", required=True, help="Path of yolov7 onnx model.")
"--model", default=None, help="Path of yolov7 onnx model.")
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,
@@ -37,12 +37,21 @@ def build_option(args):
args = parse_arguments()
if args.model is None:
model = fd.download_model(name='YOLOv7')
else:
model = args.model
# 配置runtime加载模型
runtime_option = build_option(args)
model = fd.vision.detection.YOLOv7(args.model, runtime_option=runtime_option)
model = fd.vision.detection.YOLOv7(model, 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())
# 预测结果可视化

View File

@@ -7,9 +7,9 @@ def parse_arguments():
import ast
parser = argparse.ArgumentParser()
parser.add_argument(
"--model", required=True, help="Path of yolox onnx model.")
"--model", default=None, help="Path of yolox onnx model.")
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,
@@ -37,12 +37,21 @@ def build_option(args):
args = parse_arguments()
if args.model is None:
model = fd.download_model(name='YOLOX-s')
else:
model = args.model
# 配置runtime加载模型
runtime_option = build_option(args)
model = fd.vision.detection.YOLOX(args.model, runtime_option=runtime_option)
model = fd.vision.detection.YOLOX(model, 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)
# 预测结果可视化