Skip to content

Commit

Permalink
update det example
Browse files Browse the repository at this point in the history
  • Loading branch information
jm12138 committed Nov 16, 2022
1 parent 18669b5 commit 65d4849
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 66 deletions.
17 changes: 13 additions & 4 deletions examples/vision/detection/nanodet_plus/python/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,13 +37,22 @@ 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, 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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -41,17 +41,26 @@ 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)
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,17 +48,26 @@ 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)
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)

Expand Down
21 changes: 15 additions & 6 deletions examples/vision/detection/paddledetection/python/infer_picodet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,17 +39,26 @@ 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)
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)

Expand Down
21 changes: 15 additions & 6 deletions examples/vision/detection/paddledetection/python/infer_ppyolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -41,17 +41,26 @@ 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)
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

import fastdeploy as fd
import fastdeploy.utils


def parse_arguments():
Expand Down
21 changes: 15 additions & 6 deletions examples/vision/detection/paddledetection/python/infer_yolov3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,17 +39,26 @@ 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)
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)

Expand Down
21 changes: 15 additions & 6 deletions examples/vision/detection/paddledetection/python/infer_yolox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,17 +39,26 @@ 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)
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)

Expand Down
17 changes: 13 additions & 4 deletions examples/vision/detection/scaledyolov4/python/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,13 +37,22 @@ 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, 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)

Expand Down
1 change: 0 additions & 1 deletion examples/vision/detection/yolor/python/infer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cv2

import fastdeploy as fd
import fastdeploy.utils


def parse_arguments():
Expand Down
17 changes: 13 additions & 4 deletions examples/vision/detection/yolov5/python/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 65d4849

Please sign in to comment.