在AI Studio 平台训练好的PPYOLOE权重使用FastDeploy 在本地部署
创始人
2025-05-31 23:40:45

PPYOLOE目标检测训练框架使用说明

参考博客:https://blog.csdn.net/qq_41251963/article/details/129667684

AI Studio 地址:https://aistudio.baidu.com/aistudio/projectdetail/5756078?contributionType=1

FastDeploy 环境安装

FastDeploy GitHub地址:https://github.com/PaddlePaddle/FastDeploy

参考readme文件,进行快速安装。安装前提:有Python环境,最好使用Anaconda。

  1. 进入 https://github.com/PaddlePaddle/FastDeploy#fastdeploy-quick-start-python

  1. 如果机器有显卡,可以使用GPU安装,本文演示使用CPU。

  1. 创建虚拟环境

conda create -n fastdeploy python=3.8
  1. 激活虚拟环境

conda activate fastdeploy
  1. 快速安装

1.Install FastDeploy SDK with only CPU support

pip install fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html


2. Install FastDeploy SDK with both CPU and GPU support

pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html

本文使用CPU作为演示

  1. 安装成功

  1. 下载AI Studio平台训练的PPYOLOE模型权重

打包当前文件夹,或者进入目录直接下载到本地。下载好的文件如下图所示(4个)。

  1. 使用快速测试来测试模型是否可用

detect.py

# For deployment of GPU/TensorRT, please refer to examples/vision/detection/paddledetection/python
import cv2
import fastdeploy.vision as visionim = cv2.imread("1679146167823.jpg")
model = vision.detection.PPYOLOE("part_model/model.pdmodel","part_model/model.pdiparams","part_model/infer_cfg.yml")result = model.predict(im)
print(result)vis_im = vision.vis_detection(im, result, score_threshold=0.5)
cv2.imwrite("vis_image.jpg", vis_im)
  1. 执行python detect.py 即可(由于安装CPU版本,这里默认使用OPenVINO进行推理)

其他后端推理

可参考github中readme:https://github.com/PaddlePaddle/FastDeploy/tree/develop/examples/vision/detection/paddledetection

选择ppyoloe的python 部署:

https://github.com/PaddlePaddle/FastDeploy/blob/develop/examples/vision/detection/paddledetection/python/infer_ppyoloe.py

注意修改parse_arguments函数中的参数,

  • --model_dir 导出模型所在路径

  • --image 要预测图像的路径

  • --device 使用cpu还是gpu

  • --use_trt 是否使用tensorrt 推理(如果安装的是GPU环境,建议使用,推理速度更快)

import cv2
import osimport fastdeploy as fddef parse_arguments():import argparseimport astparser = argparse.ArgumentParser()parser.add_argument("--model_dir",default="part_model",help="Path of PaddleDetection model directory")parser.add_argument("--image", default='1679146167823.jpg', help="Path of test image file.")parser.add_argument("--device",type=str,default='cpu',help="Type of inference device, support 'kunlunxin', 'cpu' or 'gpu'.")parser.add_argument("--use_trt",type=ast.literal_eval,default=False,help="Wether to use tensorrt.")return parser.parse_args()def build_option(args):option = fd.RuntimeOption()if args.device.lower() == "kunlunxin":option.use_kunlunxin()if args.device.lower() == "ascend":option.use_ascend()if args.device.lower() == "gpu":option.use_gpu()if args.use_trt:option.use_trt_backend()return optionargs = parse_arguments()if args.model_dir is None:model_dir = fd.download_model(name='ppyoloe_crn_l_300e_coco')
else:model_dir = args.model_dirmodel_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.PPYOLOE(model_file, params_file, config_file, runtime_option=runtime_option)# 预测图片检测结果
if args.image is None:image = fd.utils.get_detection_test_image()
else:image = args.image
im = cv2.imread(image)
result = model.predict(im)
print(result)# 预测结果可视化
vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
cv2.imwrite("visualized_result.jpg", vis_im)
print("Visualized result save in ./visualized_result.jpg")

运行成功

本文简单对FastDeploy的使用进行简单的介绍,FastDeploy支持多种模型(分类,检测,语义分割,OCR等)推理。详细使用参加github仓库官方文档。

请尝试将单张图片推理更改为视频推理

相关内容

热门资讯

铭记历史荣耀 积蓄统一大势 转自:贵州日报 历史回响激荡,时代步伐铿锵。岁末回望,2025年两岸关系在复杂严峻的风险挑战中...
贵阳综合保税区工业园区污染治理... 转自:贵州日报 (一)查阅途径 电话:18585743717;邮箱:1830656138...
获配金额超400亿元 浮盈比例... (来源:经济参考报) 2025年A股定增市场显著回暖,机构参与定增的热情也在攀升。Choice数据显...
补齐关键拼图 运营商首次入股个... (来源:经济参考报) 近日,朴道征信有限公司(以下简称“朴道征信”)正式引入中移投资控股有限责任公司...
《迎春图》与绵竹的春节传承 从画中走向画外:《迎春图》描绘的“打春”场景。清黄瑞鹄图据国家文物局官网  四川绵竹年画最具代表性的...