更换文档检测模型
This commit is contained in:
97
paddle_detection/deploy/fastdeploy/cpu-gpu/README.md
Normal file
97
paddle_detection/deploy/fastdeploy/cpu-gpu/README.md
Normal file
@@ -0,0 +1,97 @@
|
||||
[English](README.md) | 简体中文
|
||||
|
||||
# PaddleDetection检测模型在CPU-GPU上的部署方案—FastDeploy
|
||||
|
||||
## 1. 说明
|
||||
PaddleDetection支持利用FastDeploy在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上快速部署检测模型
|
||||
|
||||
## 2. 使用预导出的模型列表
|
||||
为了方便开发者的测试,下面提供了PaddleDetection导出的各系列模型,开发者可直接下载使用。其中精度指标来源于PaddleDetection中对各模型的介绍,详情各参考PaddleDetection中的说明。
|
||||
|
||||
### 2.1 目标检测及实例分割模型
|
||||
| 模型 | 参数大小 | 精度 | 备注 |
|
||||
|:---------------------------------------------------------------- |:----- |:----- | :------ |
|
||||
| [picodet_l_320_coco_lcnet](https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz) |23MB | Box AP 42.6% |
|
||||
| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz) |200MB | Box AP 51.4% |
|
||||
| [ppyoloe_plus_crn_m_80e_coco](https://bj.bcebos.com/fastdeploy/models/ppyoloe_plus_crn_m_80e_coco.tgz) |83.3MB | Box AP 49.8% |
|
||||
| [ppyolo_r50vd_dcn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolo_r50vd_dcn_1x_coco.tgz) | 180MB | Box AP 44.8% | 暂不支持TensorRT |
|
||||
| [ppyolov2_r101vd_dcn_365e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolov2_r101vd_dcn_365e_coco.tgz) | 282MB | Box AP 49.7% | 暂不支持TensorRT |
|
||||
| [yolov3_darknet53_270e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov3_darknet53_270e_coco.tgz) |237MB | Box AP 39.1% | |
|
||||
| [yolox_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s_300e_coco.tgz) | 35MB | Box AP 40.4% | |
|
||||
| [faster_rcnn_r50_vd_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_r50_vd_fpn_2x_coco.tgz) | 160MB | Box AP 40.8%| 暂不支持TensorRT |
|
||||
| [mask_rcnn_r50_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/mask_rcnn_r50_1x_coco.tgz) | 128M | Box AP 37.4%, Mask AP 32.8%| 暂不支持TensorRT、ORT |
|
||||
| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 24.9M | Box AP 73.8%| 暂不支持TensorRT、ORT |
|
||||
| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 106.5M | Box AP 77.8%| 暂不支持TensorRT、ORT |
|
||||
| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 29.1M | | 暂不支持TensorRT、ORT |
|
||||
| [rtmdet_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_l_300e_coco.tgz) | 224M | Box AP 51.2%| |
|
||||
| [rtmdet_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_s_300e_coco.tgz) | 42M | Box AP 44.5%| |
|
||||
| [yolov5_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_l_300e_coco.tgz) | 183M | Box AP 48.9%| |
|
||||
| [yolov5_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_s_300e_coco.tgz) | 31M | Box AP 37.6%| |
|
||||
| [yolov6_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_l_300e_coco.tgz) | 229M | Box AP 51.0%| |
|
||||
| [yolov6_s_400e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_s_400e_coco.tgz) | 68M | Box AP 43.4%| |
|
||||
| [yolov7_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_l_300e_coco.tgz) | 145M | Box AP 51.0%| |
|
||||
| [yolov7_x_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_x_300e_coco.tgz) | 277M | Box AP 53.0%| |
|
||||
| [cascade_rcnn_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_fpn_1x_coco.tgz) | 271M | Box AP 41.1%| 暂不支持TensorRT、ORT |
|
||||
| [cascade_rcnn_r50_vd_fpn_ssld_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_vd_fpn_ssld_2x_coco.tgz) | 271M | Box AP 45.0%| 暂不支持TensorRT、ORT |
|
||||
| [faster_rcnn_enhance_3x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_enhance_3x_coco.tgz) | 119M | Box AP 41.5%| 暂不支持TensorRT、ORT |
|
||||
| [fcos_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/fcos_r50_fpn_1x_coco.tgz) | 129M | Box AP 39.6%| 暂不支持TensorRT |
|
||||
| [gfl_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/gfl_r50_fpn_1x_coco.tgz) | 128M | Box AP 41.0%| 暂不支持TensorRT |
|
||||
| [ppyoloe_crn_l_80e_sliced_visdrone_640_025](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_80e_sliced_visdrone_640_025.tgz) | 200M | Box AP 31.9%| |
|
||||
| [retinanet_r101_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r101_fpn_2x_coco.tgz) | 210M | Box AP 40.6%| 暂不支持TensorRT、ORT |
|
||||
| [retinanet_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r50_fpn_1x_coco.tgz) | 136M | Box AP 37.5%| 暂不支持TensorRT、ORT |
|
||||
| [tood_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/tood_r50_fpn_1x_coco.tgz) | 130M | Box AP 42.5%| 暂不支持TensorRT、ORT |
|
||||
| [ttfnet_darknet53_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ttfnet_darknet53_1x_coco.tgz) | 178M | Box AP 33.5%| 暂不支持TensorRT、ORT |
|
||||
| [yolov8_x_500e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov8_x_500e_coco.tgz) | 265M | Box AP 53.8%
|
||||
| [yolov8_l_500e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov8_l_500e_coco.tgz) | 173M | Box AP 52.8%
|
||||
| [yolov8_m_500e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov8_m_500e_coco.tgz) | 99M | Box AP 50.2%
|
||||
| [yolov8_s_500e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov8_s_500e_coco.tgz) | 43M | Box AP 44.9%
|
||||
| [yolov8_n_500e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov8_n_500e_coco.tgz) | 13M | Box AP 37.3%
|
||||
|
||||
### 2.2 关键点检测模型
|
||||
| 模型 | 说明 | 模型格式 | 版本 |
|
||||
| :--- | :--- | :------- | :--- |
|
||||
| [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 单人关键点检测模型 | Paddle | [Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) |
|
||||
| [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 单人关键点检测模型 | Paddle | [Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) |
|
||||
| [PicoDet-S-Lcnet-Pedestrian-192x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_192x192_infer.tgz) + [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 单人关键点检测串联配置 | Paddle |[Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) |
|
||||
| [PicoDet-S-Lcnet-Pedestrian-320x320](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz) + [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 多人关键点检测串联配置 | Paddle |[Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) |
|
||||
|
||||
|
||||
## 3. 自行导出PaddleDetection部署模型
|
||||
### 3.1 模型版本
|
||||
支持[PaddleDetection](https://github.com/PaddlePaddle/PaddleDetection)大于等于2.4版本的PaddleDetection模型部署。目前FastDeploy测试过成功部署的模型:
|
||||
|
||||
- [PP-YOLOE(含PP-YOLOE+)系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/ppyoloe)
|
||||
- [PicoDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/picodet)
|
||||
- [PP-YOLO系列模型(含v2)](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/ppyolo)
|
||||
- [YOLOv3系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/yolov3)
|
||||
- [YOLOX系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/yolox)
|
||||
- [FasterRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/faster_rcnn)
|
||||
- [MaskRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/mask_rcnn)
|
||||
- [SSD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/ssd)
|
||||
- [YOLOv5系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.6/configs/yolov5)
|
||||
- [YOLOv6系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.6/configs/yolov6)
|
||||
- [YOLOv7系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.6/configs/yolov7)
|
||||
- [YOLOv8系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.6/configs/yolov8)
|
||||
- [RTMDet系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.6/configs/rtmdet)
|
||||
- [CascadeRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/cascade_rcnn)
|
||||
- [PSSDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/rcnn_enhance)
|
||||
- [RetinaNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/retinanet)
|
||||
- [PPYOLOESOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/smalldet)
|
||||
- [FCOS系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/fcos)
|
||||
- [TTFNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/ttfnet)
|
||||
- [TOOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/tood)
|
||||
- [GFL系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6/configs/gfl)
|
||||
- [PP-PicoDet + PP-TinyPose系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md)
|
||||
|
||||
### 3.2 模型导出
|
||||
PaddleDetection模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.6/deploy/EXPORT_MODEL.md),**注意**:PaddleDetection导出的模型包含`model.pdmodel`、`model.pdiparams`和`infer_cfg.yml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息
|
||||
|
||||
### 3.3 导出须知
|
||||
如果您是自行导出PaddleDetection推理模型,请注意以下问题:
|
||||
- 在导出模型时不要进行NMS的去除操作,正常导出即可
|
||||
- 如果用于跑原生TensorRT后端(非Paddle Inference后端),不要添加--trt参数
|
||||
- 导出模型时,不要添加`fuse_normalize=True`参数
|
||||
|
||||
## 4. 详细的部署示例
|
||||
- [Python部署](python)
|
||||
- [C++部署](cpp)
|
||||
@@ -0,0 +1,13 @@
|
||||
PROJECT(infer_demo C CXX)
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
|
||||
|
||||
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
|
||||
|
||||
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
|
||||
|
||||
include_directories(${FASTDEPLOY_INCS})
|
||||
|
||||
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
|
||||
add_executable(infer_tinypose_demo ${PROJECT_SOURCE_DIR}/pptinypose_infer.cc)
|
||||
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
|
||||
target_link_libraries(infer_tinypose_demo ${FASTDEPLOY_LIBS})
|
||||
142
paddle_detection/deploy/fastdeploy/cpu-gpu/cpp/README.md
Normal file
142
paddle_detection/deploy/fastdeploy/cpu-gpu/cpp/README.md
Normal file
@@ -0,0 +1,142 @@
|
||||
[English](README.md) | 简体中文
|
||||
# PaddleDetection CPU-GPU C++部署示例
|
||||
|
||||
本目录下提供`infer.cc`快速完成PPYOLOE模型包括PPYOLOE在CPU/GPU,以及GPU上通过Paddle-TensorRT加速部署的示例。
|
||||
|
||||
## 1. 说明
|
||||
PaddleDetection支持利用FastDeploy在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上快速部署PaddleDetection模型。FastDeploy目前支持的模型系列,包括但不限于`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`,`CascadeRCNN`,`PSSDet`,`RetinaNet`,`PPYOLOESOD`,`FCOS`,`TTFNet`,`TOOD`,`GFL`所有类名的构造函数和预测函数在参数上完全一致。所有模型的调用,只需要参考PPYOLOE的示例,即可快速调用。
|
||||
|
||||
## 2. 部署环境准备
|
||||
在部署前,需确认软硬件环境,同时下载预编译部署库,参考[FastDeploy安装文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装)安装FastDeploy预编译库。
|
||||
|
||||
## 3. 部署模型准备
|
||||
在部署前,请准备好您所需要运行的推理模型,你可以选择使用[预导出的推理模型](../README.md)或者[自行导出PaddleDetection部署模型](../README.md)。
|
||||
|
||||
## 4. 运行部署示例
|
||||
以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.4以上(x.x.x>=1.0.4)
|
||||
|
||||
### 4.1 目标检测示例
|
||||
```bash
|
||||
# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
|
||||
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-x.x.x.tgz
|
||||
tar xvf fastdeploy-linux-x64-gpu-x.x.x.tgz
|
||||
|
||||
# 下载部署示例代码
|
||||
git clone https://github.com/PaddlePaddle/PaddleDetection.git
|
||||
cd PaddleDetection/deploy/fastdeploy/cpu-gpu/cpp
|
||||
# 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支
|
||||
# git checkout develop
|
||||
|
||||
# 编译部署示例
|
||||
mkdir build && cd build
|
||||
mv ../fastdeploy-linux-x64-gpu-x.x.x .
|
||||
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-gpu-x.x.x
|
||||
make -j
|
||||
|
||||
# 下载PPYOLOE模型文件和测试图片
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
|
||||
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
|
||||
tar xvf ppyoloe_crn_l_300e_coco.tgz
|
||||
|
||||
# 运行部署示例
|
||||
# CPU推理
|
||||
./infer_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 0
|
||||
# GPU推理
|
||||
./infer_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 1
|
||||
# GPU上Paddle-TensorRT推理(注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
./infer_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 2
|
||||
```
|
||||
|
||||
运行完成可视化结果如下图所示
|
||||
<div align="center">
|
||||
<img src="https://user-images.githubusercontent.com/19339784/184326520-7075e907-10ed-4fad-93f8-52d0e35d4964.jpg", width=480px, height=320px />
|
||||
</div>
|
||||
|
||||
### 4.2 关键点检测示例
|
||||
```bash
|
||||
# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
|
||||
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-x.x.x.tgz
|
||||
tar xvf fastdeploy-linux-x64-gpu-x.x.x.tgz
|
||||
|
||||
# 下载部署示例代码
|
||||
git clone https://github.com/PaddlePaddle/PaddleDetection.git
|
||||
cd PaddleDetection/deploy/fastdeploy/cpu-gpu/cpp
|
||||
# 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支
|
||||
# git checkout develop
|
||||
|
||||
# 编译部署示例
|
||||
mkdir build && cd build
|
||||
mv ../fastdeploy-linux-x64-gpu-x.x.x .
|
||||
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-gpu-x.x.x
|
||||
make -j
|
||||
|
||||
# 下载PP-TinyPose模型文件和测试图片
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz
|
||||
tar -xvf PP_TinyPose_256x192_infer.tgz
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg
|
||||
|
||||
# 运行部署示例
|
||||
# CPU推理
|
||||
./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 0
|
||||
# GPU推理
|
||||
./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 1
|
||||
# GPU上Paddle-TensorRT推理(注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 2
|
||||
```
|
||||
|
||||
运行完成可视化结果如下图所示
|
||||
<div align="center">
|
||||
<img src="https://user-images.githubusercontent.com/16222477/196386764-dd51ad56-c410-4c54-9580-643f282f5a83.jpeg", width=359px, height=423px />
|
||||
</div>
|
||||
|
||||
关于如何进行多人关键点检测,请参考[PPTinyPose Pipeline示例](./det_keypoint_unite/)
|
||||
|
||||
- 注意,以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: [如何在Windows中使用FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_sdk_on_windows.md)
|
||||
- 关于如何通过FastDeploy使用更多不同的推理后端,以及如何使用不同的硬件,请参考文档:[如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md)
|
||||
|
||||
## 5. PaddleDetection C++接口
|
||||
FastDeploy目前支持的模型系列,包括但不限于`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`,`CascadeRCNN`,`PSSDet`,`RetinaNet`,`PPYOLOESOD`,`FCOS`,`TTFNet`,`TOOD`,`GFL`所有类名的构造函数和预测函数在参数上完全一致。所有模型的调用,只需要参考PPYOLOE的示例,即可快速调用。
|
||||
|
||||
### 5.1 目标检测及实例分割模型
|
||||
```c++
|
||||
fastdeploy::vision::detection::PicoDet(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::SOLOv2(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PPYOLOE(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PPYOLO(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::YOLOv3(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PaddleYOLOX(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::FasterRCNN(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::MaskRCNN(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::SSD(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PaddleYOLOv5(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PaddleYOLOv6(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PaddleYOLOv7(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PaddleYOLOv8(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::CascadeRCNN(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PSSDet(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::RetinaNet(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::PPYOLOESOD(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::FCOS(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::TOOD(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
fastdeploy::vision::detection::GFL(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
```
|
||||
|
||||
### 5.2 关键点检测模型
|
||||
```C++
|
||||
fastdeploy::vision::keypointdetection::PPTinyPose(const string& model_file, const string& params_file, const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
```
|
||||
|
||||
PaddleDetection模型加载和初始化,其中model_file, params_file为导出的Paddle部署模型格式, config_file为PaddleDetection同时导出的部署配置yaml文件
|
||||
|
||||
## 6. 更多指南
|
||||
- [PaddleDetection C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1detection.html)
|
||||
- [FastDeploy部署PaddleDetection模型概览](../../)
|
||||
- [Python部署](../python)
|
||||
|
||||
## 7. 常见问题
|
||||
- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md)
|
||||
- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md)
|
||||
- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md)
|
||||
- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md)
|
||||
- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
PROJECT(infer_demo C CXX)
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 3.12)
|
||||
|
||||
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
|
||||
|
||||
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
|
||||
|
||||
include_directories(${FASTDEPLOY_INCS})
|
||||
|
||||
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/det_keypoint_unite_infer.cc)
|
||||
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
|
||||
@@ -0,0 +1,74 @@
|
||||
[English](README.md) | 简体中文
|
||||
# PP-PicoDet + PP-TinyPose (Pipeline) CPU-GPU C++部署示例
|
||||
|
||||
本目录下提供`det_keypoint_unite_infer.cc`快速完成多人模型配置 PP-PicoDet + PP-TinyPose 在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图多人关键点检测`示例。执行如下脚本即可完成。**注意**: PP-TinyPose单模型独立部署,请参考[PP-TinyPose 单模型](../README.md)
|
||||
|
||||
## 1. 部署环境准备
|
||||
在部署前,需确认软硬件环境,同时下载预编译部署库,参考[FastDeploy安装文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装)安装FastDeploy预编译库。
|
||||
|
||||
## 2. 部署模型准备
|
||||
在部署前,请准备好您所需要运行的推理模型,你可以选择使用[预导出的推理模型](../../README.md)或者[自行导出PaddleDetection部署模型](../../README.md)。
|
||||
|
||||
## 3. 运行部署示例
|
||||
以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.4以上(x.x.x>=1.0.4)
|
||||
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
|
||||
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
|
||||
tar xvf fastdeploy-linux-x64-x.x.x.tgz
|
||||
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
|
||||
make -j
|
||||
|
||||
# 下载部署示例代码
|
||||
git clone https://github.com/PaddlePaddle/PaddleDetection.git
|
||||
cd PaddleDetection/deploy/fastdeploy/cpu-gpu/cpp/det_keypoint_unite
|
||||
# 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支
|
||||
# git checkout develop
|
||||
|
||||
# 下载PP-TinyPose和PP-PicoDet模型文件和测试图片
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz
|
||||
tar -xvf PP_TinyPose_256x192_infer.tgz
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz
|
||||
tar -xvf PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/000000018491.jpg
|
||||
|
||||
# CPU推理
|
||||
./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 0
|
||||
# GPU推理
|
||||
./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 1
|
||||
# GPU上Paddle-TensorRT推理(注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 2
|
||||
```
|
||||
|
||||
运行完成可视化结果如下图所示
|
||||
<div align="center">
|
||||
<img src="https://user-images.githubusercontent.com/16222477/196393343-eeb6b68f-0bc6-4927-871f-5ac610da7293.jpeg", width=359px, height=423px />
|
||||
</div>
|
||||
|
||||
- 注意,以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: [如何在Windows中使用FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_sdk_on_windows.md)
|
||||
- 关于如何通过FastDeploy使用更多不同的推理后端,以及如何使用不同的硬件,请参考文档:[如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md)
|
||||
|
||||
## 4. PP-TinyPose 模型串联 C++ 接口
|
||||
|
||||
```c++
|
||||
fastdeploy::pipeline::PPTinyPose(
|
||||
fastdeploy::vision::detection::PicoDet* det_model,
|
||||
fastdeploy::vision::keypointdetection::PPTinyPose* pptinypose_model)
|
||||
```
|
||||
|
||||
PPTinyPose Pipeline模型加载和初始化。det_model表示初始化后的检测模型,pptinypose_model表示初始化后的关键点检测模型。
|
||||
|
||||
|
||||
## 5. 更多指南
|
||||
- [PaddleDetection C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1detection.html)
|
||||
- [FastDeploy部署PaddleDetection模型概览](../../../)
|
||||
- [Python部署](../../python/det_keypoint_unite/)
|
||||
|
||||
## 6. 常见问题
|
||||
- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md)
|
||||
- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md)
|
||||
- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md)
|
||||
- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md)
|
||||
- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md)
|
||||
@@ -0,0 +1,205 @@
|
||||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastdeploy/vision.h"
|
||||
#include "fastdeploy/pipeline.h"
|
||||
|
||||
#ifdef WIN32
|
||||
const char sep = '\\';
|
||||
#else
|
||||
const char sep = '/';
|
||||
#endif
|
||||
|
||||
void CpuInfer(const std::string& det_model_dir,
|
||||
const std::string& tinypose_model_dir,
|
||||
const std::string& image_file) {
|
||||
auto det_model_file = det_model_dir + sep + "model.pdmodel";
|
||||
auto det_params_file = det_model_dir + sep + "model.pdiparams";
|
||||
auto det_config_file = det_model_dir + sep + "infer_cfg.yml";
|
||||
auto det_model = fastdeploy::vision::detection::PicoDet(
|
||||
det_model_file, det_params_file, det_config_file);
|
||||
if (!det_model.Initialized()) {
|
||||
std::cerr << "Detection Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto tinypose_model_file = tinypose_model_dir + sep + "model.pdmodel";
|
||||
auto tinypose_params_file = tinypose_model_dir + sep + "model.pdiparams";
|
||||
auto tinypose_config_file = tinypose_model_dir + sep + "infer_cfg.yml";
|
||||
auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose(
|
||||
tinypose_model_file, tinypose_params_file, tinypose_config_file);
|
||||
if (!tinypose_model.Initialized()) {
|
||||
std::cerr << "TinyPose Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
fastdeploy::vision::KeyPointDetectionResult res;
|
||||
|
||||
auto pipeline =fastdeploy::pipeline::PPTinyPose(&det_model, &tinypose_model);
|
||||
pipeline.detection_model_score_threshold = 0.5;
|
||||
if (!pipeline.Predict(&im, &res)) {
|
||||
std::cerr << "TinyPose Prediction Failed." << std::endl;
|
||||
return;
|
||||
} else {
|
||||
std::cout << "TinyPose Prediction Done!" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
|
||||
auto vis_im =
|
||||
fastdeploy::vision::VisKeypointDetection(im, res, 0.2);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "TinyPose visualized result saved in ./vis_result.jpg"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void GpuInfer(const std::string& det_model_dir,
|
||||
const std::string& tinypose_model_dir,
|
||||
const std::string& image_file) {
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
auto det_model_file = det_model_dir + sep + "model.pdmodel";
|
||||
auto det_params_file = det_model_dir + sep + "model.pdiparams";
|
||||
auto det_config_file = det_model_dir + sep + "infer_cfg.yml";
|
||||
auto det_model = fastdeploy::vision::detection::PicoDet(
|
||||
det_model_file, det_params_file, det_config_file, option);
|
||||
if (!det_model.Initialized()) {
|
||||
std::cerr << "Detection Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto tinypose_model_file = tinypose_model_dir + sep + "model.pdmodel";
|
||||
auto tinypose_params_file = tinypose_model_dir + sep + "model.pdiparams";
|
||||
auto tinypose_config_file = tinypose_model_dir + sep + "infer_cfg.yml";
|
||||
auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose(
|
||||
tinypose_model_file, tinypose_params_file, tinypose_config_file, option);
|
||||
if (!tinypose_model.Initialized()) {
|
||||
std::cerr << "TinyPose Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
fastdeploy::vision::KeyPointDetectionResult res;
|
||||
|
||||
auto pipeline =
|
||||
fastdeploy::pipeline::PPTinyPose(
|
||||
&det_model, &tinypose_model);
|
||||
pipeline.detection_model_score_threshold = 0.5;
|
||||
if (!pipeline.Predict(&im, &res)) {
|
||||
std::cerr << "TinyPose Prediction Failed." << std::endl;
|
||||
return;
|
||||
} else {
|
||||
std::cout << "TinyPose Prediction Done!" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
|
||||
auto vis_im =
|
||||
fastdeploy::vision::VisKeypointDetection(im, res, 0.2);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "TinyPose visualized result saved in ./vis_result.jpg"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void TrtInfer(const std::string& det_model_dir,
|
||||
const std::string& tinypose_model_dir,
|
||||
const std::string& image_file) {
|
||||
auto det_model_file = det_model_dir + sep + "model.pdmodel";
|
||||
auto det_params_file = det_model_dir + sep + "model.pdiparams";
|
||||
auto det_config_file = det_model_dir + sep + "infer_cfg.yml";
|
||||
|
||||
auto det_option = fastdeploy::RuntimeOption();
|
||||
det_option.UseGpu();
|
||||
det_option.UsePaddleInferBackend();
|
||||
// If use original Tensorrt, not Paddle-TensorRT,
|
||||
// please try `option.UseTrtBackend()`
|
||||
det_option.paddle_infer_option.enable_trt = true;
|
||||
det_option.paddle_infer_option.collect_trt_shape = true;
|
||||
det_option.trt_option.SetShape("image", {1, 3, 320, 320}, {1, 3, 320, 320},
|
||||
{1, 3, 320, 320});
|
||||
det_option.trt_option.SetShape("scale_factor", {1, 2}, {1, 2}, {1, 2});
|
||||
auto det_model = fastdeploy::vision::detection::PicoDet(
|
||||
det_model_file, det_params_file, det_config_file, det_option);
|
||||
if (!det_model.Initialized()) {
|
||||
std::cerr << "Detection Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto tinypose_model_file = tinypose_model_dir + sep + "model.pdmodel";
|
||||
auto tinypose_params_file = tinypose_model_dir + sep + "model.pdiparams";
|
||||
auto tinypose_config_file = tinypose_model_dir + sep + "infer_cfg.yml";
|
||||
auto tinypose_option = fastdeploy::RuntimeOption();
|
||||
|
||||
tinypose_option.UseGpu();
|
||||
tinypose_option.UsePaddleInferBackend();
|
||||
// If use original Tensorrt, not Paddle-TensorRT,
|
||||
// please try `option.UseTrtBackend()`
|
||||
tinypose_option.paddle_infer_option.enable_trt = true;
|
||||
tinypose_option.paddle_infer_option.collect_trt_shape = true;
|
||||
tinypose_option.trt_option.SetShape("image", {1, 3, 256, 192}, {1, 3, 256, 192},
|
||||
{1, 3, 256, 192});
|
||||
auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose(
|
||||
tinypose_model_file, tinypose_params_file, tinypose_config_file,
|
||||
tinypose_option);
|
||||
if (!tinypose_model.Initialized()) {
|
||||
std::cerr << "TinyPose Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
fastdeploy::vision::KeyPointDetectionResult res;
|
||||
|
||||
auto pipeline =
|
||||
fastdeploy::pipeline::PPTinyPose(
|
||||
&det_model, &tinypose_model);
|
||||
pipeline.detection_model_score_threshold = 0.5;
|
||||
if (!pipeline.Predict(&im, &res)) {
|
||||
std::cerr << "TinyPose Prediction Failed." << std::endl;
|
||||
return;
|
||||
} else {
|
||||
std::cout << "TinyPose Prediction Done!" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
|
||||
auto vis_im =
|
||||
fastdeploy::vision::VisKeypointDetection(im, res, 0.2);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "TinyPose visualized result saved in ./vis_result.jpg"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 5) {
|
||||
std::cout << "Usage: infer_demo path/to/detection_model_dir "
|
||||
"path/to/pptinypose_model_dir path/to/image run_option, "
|
||||
"e.g ./infer_model ./picodet_model_dir ./pptinypose_model_dir "
|
||||
"./test.jpeg 0"
|
||||
<< std::endl;
|
||||
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
|
||||
"with gpu; 2: run with gpu and use tensorrt backend;"
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (std::atoi(argv[4]) == 0) {
|
||||
CpuInfer(argv[1], argv[2], argv[3]);
|
||||
} else if (std::atoi(argv[4]) == 1) {
|
||||
GpuInfer(argv[1], argv[2], argv[3]);
|
||||
} else if (std::atoi(argv[4]) == 2) {
|
||||
TrtInfer(argv[1], argv[2], argv[3]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
134
paddle_detection/deploy/fastdeploy/cpu-gpu/cpp/infer.cc
Normal file
134
paddle_detection/deploy/fastdeploy/cpu-gpu/cpp/infer.cc
Normal file
@@ -0,0 +1,134 @@
|
||||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastdeploy/vision.h"
|
||||
|
||||
#ifdef WIN32
|
||||
const char sep = '\\';
|
||||
#else
|
||||
const char sep = '/';
|
||||
#endif
|
||||
|
||||
void CpuInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto config_file = model_dir + sep + "infer_cfg.yml";
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseCpu();
|
||||
auto model = fastdeploy::vision::detection::PPYOLOE(model_file, params_file,
|
||||
config_file, option);
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
|
||||
fastdeploy::vision::DetectionResult res;
|
||||
if (!model.Predict(im, &res)) {
|
||||
std::cerr << "Failed to predict." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
}
|
||||
|
||||
void GpuInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto config_file = model_dir + sep + "infer_cfg.yml";
|
||||
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
auto model = fastdeploy::vision::detection::PPYOLOE(model_file, params_file,
|
||||
config_file, option);
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
|
||||
fastdeploy::vision::DetectionResult res;
|
||||
if (!model.Predict(im, &res)) {
|
||||
std::cerr << "Failed to predict." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
}
|
||||
|
||||
void TrtInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto config_file = model_dir + sep + "infer_cfg.yml";
|
||||
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
option.UsePaddleInferBackend();
|
||||
// If use original Tensorrt, not Paddle-TensorRT,
|
||||
// please try `option.UseTrtBackend()`
|
||||
option.paddle_infer_option.enable_trt = true;
|
||||
option.paddle_infer_option.collect_trt_shape = true;
|
||||
option.trt_option.SetShape("image", {1, 3, 640, 640}, {1, 3, 640, 640},
|
||||
{1, 3, 640, 640});
|
||||
option.trt_option.SetShape("scale_factor", {1, 2}, {1, 2}, {1, 2});
|
||||
auto model = fastdeploy::vision::detection::PPYOLOE(model_file, params_file,
|
||||
config_file, option);
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
|
||||
fastdeploy::vision::DetectionResult res;
|
||||
if (!model.Predict(im, &res)) {
|
||||
std::cerr << "Failed to predict." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 4) {
|
||||
std::cout
|
||||
<< "Usage: infer_demo path/to/model_dir path/to/image run_option, "
|
||||
"e.g ./infer_demo ./ppyoloe_model_dir ./test.jpeg 0"
|
||||
<< std::endl;
|
||||
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
|
||||
"with gpu; 2: run with gpu and use tensorrt backend"
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (std::atoi(argv[3]) == 0) {
|
||||
CpuInfer(argv[1], argv[2]);
|
||||
} else if (std::atoi(argv[3]) == 1) {
|
||||
GpuInfer(argv[1], argv[2]);
|
||||
} else if (std::atoi(argv[3]) == 2) {
|
||||
TrtInfer(argv[1], argv[2]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastdeploy/vision.h"
|
||||
|
||||
#ifdef WIN32
|
||||
const char sep = '\\';
|
||||
#else
|
||||
const char sep = '/';
|
||||
#endif
|
||||
|
||||
void CpuInfer(const std::string& tinypose_model_dir,
|
||||
const std::string& image_file) {
|
||||
auto tinypose_model_file = tinypose_model_dir + sep + "model.pdmodel";
|
||||
auto tinypose_params_file = tinypose_model_dir + sep + "model.pdiparams";
|
||||
auto tinypose_config_file = tinypose_model_dir + sep + "infer_cfg.yml";
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseCpu();
|
||||
auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose(
|
||||
tinypose_model_file, tinypose_params_file, tinypose_config_file, option);
|
||||
if (!tinypose_model.Initialized()) {
|
||||
std::cerr << "TinyPose Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
fastdeploy::vision::KeyPointDetectionResult res;
|
||||
if (!tinypose_model.Predict(&im, &res)) {
|
||||
std::cerr << "TinyPose Prediction Failed." << std::endl;
|
||||
return;
|
||||
} else {
|
||||
std::cout << "TinyPose Prediction Done!" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
|
||||
auto tinypose_vis_im =
|
||||
fastdeploy::vision::VisKeypointDetection(im, res, 0.5);
|
||||
cv::imwrite("tinypose_vis_result.jpg", tinypose_vis_im);
|
||||
std::cout << "TinyPose visualized result saved in ./tinypose_vis_result.jpg"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void GpuInfer(const std::string& tinypose_model_dir,
|
||||
const std::string& image_file) {
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
|
||||
auto tinypose_model_file = tinypose_model_dir + sep + "model.pdmodel";
|
||||
auto tinypose_params_file = tinypose_model_dir + sep + "model.pdiparams";
|
||||
auto tinypose_config_file = tinypose_model_dir + sep + "infer_cfg.yml";
|
||||
auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose(
|
||||
tinypose_model_file, tinypose_params_file, tinypose_config_file, option);
|
||||
if (!tinypose_model.Initialized()) {
|
||||
std::cerr << "TinyPose Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
fastdeploy::vision::KeyPointDetectionResult res;
|
||||
if (!tinypose_model.Predict(&im, &res)) {
|
||||
std::cerr << "TinyPose Prediction Failed." << std::endl;
|
||||
return;
|
||||
} else {
|
||||
std::cout << "TinyPose Prediction Done!" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
|
||||
auto tinypose_vis_im =
|
||||
fastdeploy::vision::VisKeypointDetection(im, res, 0.5);
|
||||
cv::imwrite("tinypose_vis_result.jpg", tinypose_vis_im);
|
||||
std::cout << "TinyPose visualized result saved in ./tinypose_vis_result.jpg"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void TrtInfer(const std::string& tinypose_model_dir,
|
||||
const std::string& image_file) {
|
||||
auto tinypose_model_file = tinypose_model_dir + sep + "model.pdmodel";
|
||||
auto tinypose_params_file = tinypose_model_dir + sep + "model.pdiparams";
|
||||
auto tinypose_config_file = tinypose_model_dir + sep + "infer_cfg.yml";
|
||||
auto tinypose_option = fastdeploy::RuntimeOption();
|
||||
tinypose_option.UseGpu();
|
||||
tinypose_option.UsePaddleInferBackend();
|
||||
// If use original Tensorrt, not Paddle-TensorRT,
|
||||
// please try `option.UseTrtBackend()`
|
||||
tinypose_option.paddle_infer_option.enable_trt = true;
|
||||
tinypose_option.paddle_infer_option.collect_trt_shape = true;
|
||||
tinypose_option.trt_option.SetShape("image", {1, 3, 256, 192}, {1, 3, 256, 192},
|
||||
{1, 3, 256, 192});
|
||||
|
||||
auto tinypose_model = fastdeploy::vision::keypointdetection::PPTinyPose(
|
||||
tinypose_model_file, tinypose_params_file, tinypose_config_file,
|
||||
tinypose_option);
|
||||
if (!tinypose_model.Initialized()) {
|
||||
std::cerr << "TinyPose Model Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
fastdeploy::vision::KeyPointDetectionResult res;
|
||||
if (!tinypose_model.Predict(&im, &res)) {
|
||||
std::cerr << "TinyPose Prediction Failed." << std::endl;
|
||||
return;
|
||||
} else {
|
||||
std::cout << "TinyPose Prediction Done!" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << res.Str() << std::endl;
|
||||
|
||||
auto tinypose_vis_im =
|
||||
fastdeploy::vision::VisKeypointDetection(im, res, 0.5);
|
||||
cv::imwrite("tinypose_vis_result.jpg", tinypose_vis_im);
|
||||
std::cout << "TinyPose visualized result saved in ./tinypose_vis_result.jpg"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 4) {
|
||||
std::cout << "Usage: infer_demo path/to/pptinypose_model_dir path/to/image "
|
||||
"run_option, "
|
||||
"e.g ./infer_demo ./pptinypose_model_dir ./test.jpeg 0"
|
||||
<< std::endl;
|
||||
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
|
||||
"with gpu; 2: run with gpu and use tensorrt backend;"
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (std::atoi(argv[3]) == 0) {
|
||||
CpuInfer(argv[1], argv[2]);
|
||||
} else if (std::atoi(argv[3]) == 1) {
|
||||
GpuInfer(argv[1], argv[2]);
|
||||
} else if (std::atoi(argv[3]) == 2) {
|
||||
TrtInfer(argv[1], argv[2]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
126
paddle_detection/deploy/fastdeploy/cpu-gpu/python/README.md
Normal file
126
paddle_detection/deploy/fastdeploy/cpu-gpu/python/README.md
Normal file
@@ -0,0 +1,126 @@
|
||||
[English](README.md) | 简体中文
|
||||
# PaddleDetection CPU-GPU Python部署示例
|
||||
|
||||
本目录下提供`infer.py`快速完成PPYOLOE模型包括PPYOLOE在CPU/GPU,以及GPU上通过Paddle-TensorRT加速部署的示例。
|
||||
|
||||
## 1. 说明
|
||||
PaddleDetection支持利用FastDeploy在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上快速部署PaddleDetection模型。FastDeploy目前支持的模型系列,包括但不限于`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`,`CascadeRCNN`,`PSSDet`,`RetinaNet`,`PPYOLOESOD`,`FCOS`,`TTFNet`,`TOOD`,`GFL`所有类名的构造函数和预测函数在参数上完全一致。所有模型的调用,只需要参考PPYOLOE的示例,即可快速调用。
|
||||
|
||||
## 2. 部署环境准备
|
||||
在部署前,需确认软硬件环境,同时下载预编译部署库,参考[FastDeploy安装文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装)安装FastDeploy预编译库。
|
||||
|
||||
## 3. 部署模型准备
|
||||
在部署前,请准备好您所需要运行的推理模型,你可以选择使用[预导出的推理模型](../README.md)或者[自行导出PaddleDetection部署模型](../README.md)。
|
||||
|
||||
## 4. 运行部署示例
|
||||
以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.4以上(x.x.x>=1.0.4)
|
||||
|
||||
### 4.1 目标检测示例
|
||||
```bash
|
||||
# 下载部署示例代码
|
||||
git clone https://github.com/PaddlePaddle/PaddleDetection.git
|
||||
cd PaddleDetection/deploy/fastdeploy/cpu-gpu/python
|
||||
# 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支
|
||||
# git checkout develop
|
||||
|
||||
# 下载PPYOLOE模型文件和测试图片
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
|
||||
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
|
||||
tar xvf ppyoloe_crn_l_300e_coco.tgz
|
||||
|
||||
# 运行部署示例
|
||||
# CPU推理
|
||||
python infer.py --model_dir ppyoloe_crn_l_300e_coco --image_file 000000014439.jpg --device cpu
|
||||
# GPU推理
|
||||
python infer.py --model_dir ppyoloe_crn_l_300e_coco --image_file 000000014439.jpg --device gpu
|
||||
# GPU上Paddle-TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
python infer.py --model_dir ppyoloe_crn_l_300e_coco --image_file 000000014439.jpg --device gpu --use_trt True
|
||||
```
|
||||
|
||||
运行完成可视化结果如下图所示
|
||||
<div align="center">
|
||||
<img src="https://user-images.githubusercontent.com/19339784/184326520-7075e907-10ed-4fad-93f8-52d0e35d4964.jpg", width=480px, height=320px />
|
||||
</div>
|
||||
|
||||
### 4.2 关键点检测示例
|
||||
```bash
|
||||
# 下载部署示例代码
|
||||
git clone https://github.com/PaddlePaddle/PaddleDetection.git
|
||||
cd PaddleDetection/deploy/fastdeploy/cpu-gpu/python
|
||||
# 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支
|
||||
# git checkout develop
|
||||
|
||||
# 下载PP-TinyPose模型文件和测试图片
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz
|
||||
tar -xvf PP_TinyPose_256x192_infer.tgz
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg
|
||||
|
||||
# 运行部署示例
|
||||
# CPU推理
|
||||
python pptinypose_infer.py --model_dir PP_TinyPose_256x192_infer --image_file hrnet_demo.jpg --device cpu
|
||||
# GPU推理
|
||||
python pptinypose_infer.py --model_dir PP_TinyPose_256x192_infer --image_file hrnet_demo.jpg --device gpu
|
||||
# GPU上Paddle-TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
python pptinypose_infer.py --model_dir PP_TinyPose_256x192_infer --image_file hrnet_demo.jpg --device gpu --use_trt True
|
||||
```
|
||||
|
||||
运行完成可视化结果如下图所示
|
||||
<div align="center">
|
||||
<img src="https://user-images.githubusercontent.com/16222477/196386764-dd51ad56-c410-4c54-9580-643f282f5a83.jpeg", width=359px, height=423px />
|
||||
</div>
|
||||
|
||||
关于如何进行多人关键点检测,请参考[PPTinyPose Pipeline示例](./det_keypoint_unite/)
|
||||
|
||||
## 5. 部署示例选项说明
|
||||
|
||||
|参数|含义|默认值
|
||||
|---|---|---|
|
||||
|--model_dir|指定模型文件夹所在的路径|None|
|
||||
|--image_file|指定测试图片所在的路径|None|
|
||||
|--device|指定即将运行的硬件类型,支持的值为`[cpu, gpu]`,当设置为cpu时,可运行在x86 cpu/arm cpu等cpu上|cpu|
|
||||
|--use_trt|是否使用trt,该项只在device为gpu时有效|False|
|
||||
|
||||
## 6. PaddleDetection Python接口
|
||||
FastDeploy目前支持的模型系列,包括但不限于`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`,`CascadeRCNN`,`PSSDet`,`RetinaNet`,`PPYOLOESOD`,`FCOS`,`TTFNet`,`TOOD`,`GFL`所有类名的构造函数和预测函数在参数上完全一致。所有模型的调用,只需要参考PPYOLOE的示例,即可快速调用。
|
||||
|
||||
### 6.1 目标检测及实例分割模型
|
||||
```python
|
||||
fastdeploy.vision.detection.PPYOLOE(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PicoDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PaddleYOLOX(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.YOLOv3(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PPYOLO(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.FasterRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.MaskRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.SSD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PaddleYOLOv5(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PaddleYOLOv6(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PaddleYOLOv7(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.RTMDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.CascadeRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PSSDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.RetinaNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.PPYOLOESOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.FCOS(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.TTFNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.TOOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
fastdeploy.vision.detection.GFL(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
```
|
||||
### 6.2 关键点检测模型
|
||||
```python
|
||||
fd.vision.keypointdetection.PPTinyPose(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
|
||||
```
|
||||
|
||||
PaddleDetection模型加载和初始化,其中model_file, params_file为导出的Paddle部署模型格式, config_file为PaddleDetection同时导出的部署配置yaml文件
|
||||
|
||||
## 7. 更多指南
|
||||
- [PaddleDetection Python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/object_detection.html)
|
||||
- [FastDeploy部署PaddleDetection模型概览](../../)
|
||||
- [C++部署](../cpp)
|
||||
|
||||
## 8. 常见问题
|
||||
- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md)
|
||||
- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md)
|
||||
- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md)
|
||||
- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md)
|
||||
- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md)
|
||||
@@ -0,0 +1,70 @@
|
||||
[English](README.md) | 简体中文
|
||||
# PP-PicoDet + PP-TinyPose (Pipeline) CPU-GPU Python部署示例
|
||||
|
||||
本目录下提供`det_keypoint_unite_infer.py`快速完成多人模型配置 PP-PicoDet + PP-TinyPose 在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图多人关键点检测`示例。执行如下脚本即可完成.**注意**: PP-TinyPose单模型独立部署,请参考[PP-TinyPose 单模型](../README.md)
|
||||
|
||||
## 1. 部署环境准备
|
||||
在部署前,需确认软硬件环境,同时下载预编译部署库,参考[FastDeploy安装文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装)安装FastDeploy预编译库。
|
||||
|
||||
## 2. 部署模型准备
|
||||
在部署前,请准备好您所需要运行的推理模型,你可以选择使用[预导出的推理模型](../../README.md)或者[自行导出PaddleDetection部署模型](../../README.md)。
|
||||
|
||||
## 3. 运行部署示例
|
||||
|
||||
```bash
|
||||
# 下载部署示例代码
|
||||
git clone https://github.com/PaddlePaddle/PaddleDetection.git
|
||||
cd PaddleDetection/deploy/fastdeploy/cpu-gpu/python/det_keypoint_unite
|
||||
# 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支
|
||||
# git checkout develop
|
||||
|
||||
# 下载PP-TinyPose模型文件和测试图片
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz
|
||||
tar -xvf PP_TinyPose_256x192_infer.tgz
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz
|
||||
tar -xvf PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/000000018491.jpg
|
||||
# CPU推理
|
||||
python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image_file 000000018491.jpg --device cpu
|
||||
# GPU推理
|
||||
python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image_file 000000018491.jpg --device gpu
|
||||
# GPU上Paddle-TensorRT推理(注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image_file 000000018491.jpg --device gpu --use_trt True
|
||||
```
|
||||
|
||||
运行完成可视化结果如下图所示
|
||||
<div align="center">
|
||||
<img src="https://user-images.githubusercontent.com/16222477/196393343-eeb6b68f-0bc6-4927-871f-5ac610da7293.jpeg", width=640px, height=427px />
|
||||
</div>
|
||||
|
||||
- 关于如何通过FastDeploy使用更多不同的推理后端,以及如何使用不同的硬件,请参考文档:[如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md)
|
||||
|
||||
## 4. 部署示例选项说明
|
||||
|
||||
|参数|含义|默认值
|
||||
|---|---|---|
|
||||
|--tinypose_model_dir|指定关键点模型文件夹所在的路径|None|
|
||||
|--det_model_dir|指定目标模型文件夹所在的路径|None|
|
||||
|--image_file|指定测试图片所在的路径|None|
|
||||
|--device|指定即将运行的硬件类型,支持的值为`[cpu, gpu]`,当设置为cpu时,可运行在x86 cpu/arm cpu等cpu上|cpu|
|
||||
|--use_trt|是否使用trt,该项只在device为gpu时有效|False|
|
||||
|
||||
## 5. PPTinyPose 模型串联 Python接口
|
||||
|
||||
```python
|
||||
fd.pipeline.PPTinyPose(det_model=None, pptinypose_model=None)
|
||||
```
|
||||
|
||||
PPTinyPose Pipeline 模型加载和初始化,其中det_model是使用`fd.vision.detection.PicoDet`初始化的检测模型,pptinypose_model是使用`fd.vision.keypointdetection.PPTinyPose`初始化的关键点检测模型。
|
||||
|
||||
## 6. 更多指南
|
||||
- [PaddleDetection Python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/object_detection.html)
|
||||
- [FastDeploy部署PaddleDetection模型概览](../../../)
|
||||
- [C++部署](../../cpp/)
|
||||
|
||||
## 7. 常见问题
|
||||
- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md)
|
||||
- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md)
|
||||
- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md)
|
||||
- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md)
|
||||
- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md)
|
||||
@@ -0,0 +1,101 @@
|
||||
import fastdeploy as fd
|
||||
import cv2
|
||||
import os
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
import argparse
|
||||
import ast
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--tinypose_model_dir",
|
||||
required=True,
|
||||
help="path of paddletinypose model directory")
|
||||
parser.add_argument(
|
||||
"--det_model_dir", help="path of paddledetection model directory")
|
||||
parser.add_argument(
|
||||
"--image_file", required=True, help="path of test image file.")
|
||||
parser.add_argument(
|
||||
"--device",
|
||||
type=str,
|
||||
default='cpu',
|
||||
help="type of inference device, support '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_picodet_option(args):
|
||||
option = fd.RuntimeOption()
|
||||
|
||||
if args.device.lower() == "gpu":
|
||||
option.use_gpu()
|
||||
|
||||
if args.use_trt:
|
||||
option.use_paddle_infer_backend()
|
||||
# If use original Tensorrt, not Paddle-TensorRT,
|
||||
# please try `option.use_trt_backend()`
|
||||
option.paddle_infer_option.enable_trt = True
|
||||
option.paddle_infer_option.collect_trt_shape = True
|
||||
option.trt_option.set_shape("image", [1, 3, 320, 320], [1, 3, 320, 320],
|
||||
[1, 3, 320, 320])
|
||||
option.trt_option.set_shape("scale_factor", [1, 2], [1, 2], [1, 2])
|
||||
return option
|
||||
|
||||
|
||||
def build_tinypose_option(args):
|
||||
option = fd.RuntimeOption()
|
||||
|
||||
if args.device.lower() == "gpu":
|
||||
option.use_gpu()
|
||||
|
||||
if args.use_trt:
|
||||
option.use_paddle_infer_backend()
|
||||
# If use original Tensorrt, not Paddle-TensorRT,
|
||||
# please try `option.use_trt_backend()`
|
||||
option.paddle_infer_option.enable_trt = True
|
||||
option.paddle_infer_option.collect_trt_shape = True
|
||||
option.trt_option.set_shape("image", [1, 3, 256, 192], [1, 3, 256, 192],
|
||||
[1, 3, 256, 192])
|
||||
return option
|
||||
|
||||
|
||||
args = parse_arguments()
|
||||
picodet_model_file = os.path.join(args.det_model_dir, "model.pdmodel")
|
||||
picodet_params_file = os.path.join(args.det_model_dir, "model.pdiparams")
|
||||
picodet_config_file = os.path.join(args.det_model_dir, "infer_cfg.yml")
|
||||
|
||||
# setup runtime
|
||||
runtime_option = build_picodet_option(args)
|
||||
det_model = fd.vision.detection.PicoDet(
|
||||
picodet_model_file,
|
||||
picodet_params_file,
|
||||
picodet_config_file,
|
||||
runtime_option=runtime_option)
|
||||
|
||||
tinypose_model_file = os.path.join(args.tinypose_model_dir, "model.pdmodel")
|
||||
tinypose_params_file = os.path.join(args.tinypose_model_dir, "model.pdiparams")
|
||||
tinypose_config_file = os.path.join(args.tinypose_model_dir, "infer_cfg.yml")
|
||||
# setup runtime
|
||||
runtime_option = build_tinypose_option(args)
|
||||
tinypose_model = fd.vision.keypointdetection.PPTinyPose(
|
||||
tinypose_model_file,
|
||||
tinypose_params_file,
|
||||
tinypose_config_file,
|
||||
runtime_option=runtime_option)
|
||||
|
||||
# predict
|
||||
im = cv2.imread(args.image_file)
|
||||
pipeline = fd.pipeline.PPTinyPose(det_model, tinypose_model)
|
||||
pipeline.detection_model_score_threshold = 0.5
|
||||
pipeline_result = pipeline.predict(im)
|
||||
print("Paddle TinyPose Result:\n", pipeline_result)
|
||||
|
||||
# visualize
|
||||
vis_im = fd.vision.vis_keypoint_detection(
|
||||
im, pipeline_result, conf_threshold=0.2)
|
||||
cv2.imwrite("visualized_result.jpg", vis_im)
|
||||
print("TinyPose visualized result save in ./visualized_result.jpg")
|
||||
74
paddle_detection/deploy/fastdeploy/cpu-gpu/python/infer.py
Normal file
74
paddle_detection/deploy/fastdeploy/cpu-gpu/python/infer.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import cv2
|
||||
import os
|
||||
|
||||
import fastdeploy as fd
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
import argparse
|
||||
import ast
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--model_dir", required=True, help="Path of PaddleDetection model.")
|
||||
parser.add_argument(
|
||||
"--image_file", type=str, required=True, help="Path of test image file.")
|
||||
parser.add_argument(
|
||||
"--device",
|
||||
type=str,
|
||||
default='cpu',
|
||||
help="Type of inference device, support, '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() == "gpu":
|
||||
option.use_gpu()
|
||||
|
||||
if args.use_trt:
|
||||
option.use_paddle_infer_backend()
|
||||
# If use original Tensorrt, not Paddle-TensorRT,
|
||||
# please try `option.use_trt_backend()`
|
||||
option.paddle_infer_option.enable_trt = True
|
||||
option.paddle_infer_option.collect_trt_shape = True
|
||||
option.trt_option.set_shape("image", [1, 3, 640, 640], [1, 3, 640, 640],
|
||||
[1, 3, 640, 640])
|
||||
option.trt_option.set_shape("scale_factor", [1, 2], [1, 2], [1, 2])
|
||||
return option
|
||||
|
||||
|
||||
args = parse_arguments()
|
||||
|
||||
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")
|
||||
|
||||
# settting for runtime
|
||||
runtime_option = build_option(args)
|
||||
model = fd.vision.detection.PPYOLOE(
|
||||
model_file, params_file, config_file, runtime_option=runtime_option)
|
||||
|
||||
# predict
|
||||
if args.image_file is None:
|
||||
image_file = fd.utils.get_detection_test_image()
|
||||
else:
|
||||
image_file = args.image_file
|
||||
im = cv2.imread(image_file)
|
||||
result = model.predict(im)
|
||||
print(result)
|
||||
|
||||
# visualize
|
||||
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")
|
||||
@@ -0,0 +1,67 @@
|
||||
import fastdeploy as fd
|
||||
import cv2
|
||||
import os
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
import argparse
|
||||
import ast
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--model_dir",
|
||||
required=True,
|
||||
help="path of PP-TinyPose model directory")
|
||||
parser.add_argument(
|
||||
"--image_file", required=True, help="path of test image file.")
|
||||
parser.add_argument(
|
||||
"--device",
|
||||
type=str,
|
||||
default='cpu',
|
||||
help="type of inference device, support '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() == "gpu":
|
||||
option.use_gpu()
|
||||
|
||||
if args.use_trt:
|
||||
option.use_paddle_infer_backend()
|
||||
# If use original Tensorrt, not Paddle-TensorRT,
|
||||
# please try `option.use_trt_backend()`
|
||||
option.paddle_infer_option.enable_trt = True
|
||||
option.paddle_infer_option.collect_trt_shape = True
|
||||
option.trt_option.set_shape("image", [1, 3, 256, 192], [1, 3, 256, 192],
|
||||
[1, 3, 256, 192])
|
||||
return option
|
||||
|
||||
|
||||
args = parse_arguments()
|
||||
|
||||
tinypose_model_file = os.path.join(args.model_dir, "model.pdmodel")
|
||||
tinypose_params_file = os.path.join(args.model_dir, "model.pdiparams")
|
||||
tinypose_config_file = os.path.join(args.model_dir, "infer_cfg.yml")
|
||||
# setup runtime
|
||||
runtime_option = build_option(args)
|
||||
tinypose_model = fd.vision.keypointdetection.PPTinyPose(
|
||||
tinypose_model_file,
|
||||
tinypose_params_file,
|
||||
tinypose_config_file,
|
||||
runtime_option=runtime_option)
|
||||
# predict
|
||||
im = cv2.imread(args.image_file)
|
||||
tinypose_result = tinypose_model.predict(im)
|
||||
print("Paddle TinyPose Result:\n", tinypose_result)
|
||||
|
||||
# visualize
|
||||
vis_im = fd.vision.vis_keypoint_detection(
|
||||
im, tinypose_result, conf_threshold=0.5)
|
||||
cv2.imwrite("visualized_result.jpg", vis_im)
|
||||
print("TinyPose visualized result save in ./visualized_result.jpg")
|
||||
Reference in New Issue
Block a user