mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
[Backend] Add KunlunXin XPU deploy support (#894)
Revert "Revert "[Backend] Add KunlunXin XPU deploy support" (#893)"
This reverts commit 0990ab9b50
.
This commit is contained in:
11
examples/vision/detection/yolov5/python/README.md
Normal file → Executable file
11
examples/vision/detection/yolov5/python/README.md
Normal file → Executable file
@@ -13,15 +13,18 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git
|
||||
cd examples/vision/detection/yolov5/python/
|
||||
|
||||
#下载yolov5模型文件和测试图片
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar
|
||||
tar -xf yolov5s_infer.tar
|
||||
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
|
||||
|
||||
# CPU推理
|
||||
python infer.py --model yolov5s.onnx --image 000000014439.jpg --device cpu
|
||||
python infer.py --model yolov5s_infer --image 000000014439.jpg --device cpu
|
||||
# GPU推理
|
||||
python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu
|
||||
python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu
|
||||
# GPU上使用TensorRT推理
|
||||
python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu --use_trt True
|
||||
python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True
|
||||
# XPU推理
|
||||
python infer.py --model yolov5s_infer --image 000000014439.jpg --device xpu
|
||||
```
|
||||
|
||||
运行完成可视化结果如下图所示
|
||||
|
21
examples/vision/detection/yolov5/python/infer.py
Normal file → Executable file
21
examples/vision/detection/yolov5/python/infer.py
Normal file → Executable file
@@ -1,20 +1,20 @@
|
||||
import fastdeploy as fd
|
||||
import cv2
|
||||
import os
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
import argparse
|
||||
import ast
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--model", default=None, help="Path of yolov5 onnx model.")
|
||||
parser.add_argument("--model", default=None, help="Path of yolov5 model.")
|
||||
parser.add_argument(
|
||||
"--image", default=None, help="Path of test image file.")
|
||||
parser.add_argument(
|
||||
"--device",
|
||||
type=str,
|
||||
default='cpu',
|
||||
help="Type of inference device, support 'cpu' or 'gpu'.")
|
||||
help="Type of inference device, support 'cpu' or 'gpu' or 'xpu'.")
|
||||
parser.add_argument(
|
||||
"--use_trt",
|
||||
type=ast.literal_eval,
|
||||
@@ -25,6 +25,8 @@ def parse_arguments():
|
||||
|
||||
def build_option(args):
|
||||
option = fd.RuntimeOption()
|
||||
if args.device.lower() == "xpu":
|
||||
option.use_xpu()
|
||||
|
||||
if args.device.lower() == "gpu":
|
||||
option.use_gpu()
|
||||
@@ -37,14 +39,15 @@ 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(model, runtime_option=runtime_option)
|
||||
model_file = os.path.join(args.model, "model.pdmodel")
|
||||
params_file = os.path.join(args.model, "model.pdiparams")
|
||||
model = fd.vision.detection.YOLOv5(
|
||||
model_file,
|
||||
params_file,
|
||||
runtime_option=runtime_option,
|
||||
model_format=fd.ModelFormat.PADDLE)
|
||||
|
||||
# 预测图片检测结果
|
||||
if args.image is None:
|
||||
|
Reference in New Issue
Block a user