mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
[Model] Add tinypose single && pipeline model (#177)
* Add tinypose model * Add PPTinypose python API * Fix picodet preprocess bug && Add Tinypose examples * Update tinypose example code * Update ppseg preprocess if condition * Update ppseg backend support type * Update permute.h * Update README.md * Update code with comments * Move files dir * Delete premute.cc * Add single model pptinypose * Delete pptinypose old code in ppdet * Code format * Add ppdet + pptinypose pipeline model * Fix bug for posedetpipeline * Change Frontend to ModelFormat * Change Frontend to ModelFormat in __init__.py * Add python posedetpipeline/ * Update pptinypose example dir name * Update README.md * Update README.md * Update README.md * Update README.md * Create keypointdetection_result.md * Create README.md * Create README.md * Create README.md * Update README.md * Update README.md * Create README.md * Fix det_keypoint_unite_infer.py bug * Create README.md * Update PP-Tinypose by comment * Update by comment * Add pipeline directory * Add pptinypose dir * Update pptinypose to align accuracy * Addd warpAffine processor * Update GetCpuMat to GetOpenCVMat * Add comment for pptinypose && pipline * Update docs/main_page.md * Add README.md for pptinypose * Add README for det_keypoint_unite * Remove ENABLE_PIPELINE option * Remove ENABLE_PIPELINE option * Change pptinypose default backend * PP-TinyPose Pipeline support multi PP-Detection models * Update pp-tinypose comment * Update by comments * Add single test example Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# PP-PicoDet + PP-TinyPose (Pipeline) Python部署示例
|
||||
|
||||
在部署前,需确认以下两个步骤
|
||||
|
||||
- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
|
||||
- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
|
||||
|
||||
本目录下提供`det_keypoint_unite_infer.py`快速完成多人模型配置 PP-PicoDet + PP-TinyPose 在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图多人关键点检测`示例。执行如下脚本即可完成
|
||||
>> **注意**: PP-TinyPose单模型独立部署,请参考[PP-TinyPose 单模型](../../tiny_pose//python/README.md)
|
||||
|
||||
```bash
|
||||
#下载部署示例代码
|
||||
git clone https://github.com/PaddlePaddle/FastDeploy.git
|
||||
cd FastDeploy/examples/vision/keypointdetection/det_keypoint_unite/python
|
||||
|
||||
# 下载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 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 000000018491.jpg --device gpu
|
||||
# GPU上使用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 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>
|
||||
|
||||
## PPTinyPosePipeline Python接口
|
||||
|
||||
```python
|
||||
fd.pipeline.PPTinyPose(det_model=None, pptinypose_model=None)
|
||||
```
|
||||
|
||||
PPTinyPosePipeline模型加载和初始化,其中det_model是使用`fd.vision.detection.PicoDet`[参考Detection文档](../../../detection/paddledetection/python/)初始化的检测模型,pptinypose_model是使用`fd.vision.keypointdetection.PPTinyPose`[参考PP-TinyPose文档](../../tiny_pose/python/)初始化的检测模型
|
||||
|
||||
**参数**
|
||||
|
||||
> * **det_model**(str): 初始化后的检测模型
|
||||
> * **pptinypose_model**(str): 初始化后的PP-TinyPose模型
|
||||
|
||||
### predict函数
|
||||
|
||||
> ```python
|
||||
> PPTinyPosePipeline.predict(input_image)
|
||||
> ```
|
||||
>
|
||||
> 模型预测结口,输入图像直接输出检测结果。
|
||||
>
|
||||
> **参数**
|
||||
>
|
||||
> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式
|
||||
|
||||
> **返回**
|
||||
>
|
||||
> > 返回`fastdeploy.vision.KeyPointDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/)
|
||||
|
||||
### 类成员属性
|
||||
#### 后处理参数
|
||||
> > * **detection_model_score_threshold**(bool):
|
||||
输入PP-TinyPose模型前,Detectin模型过滤检测框的分数阈值
|
||||
|
||||
## 其它文档
|
||||
|
||||
- [Pipeline 模型介绍](..)
|
||||
- [Pipeline C++部署](../cpp)
|
||||
- [模型预测结果说明](../../../../../docs/api/vision_results/)
|
||||
- [如何切换模型推理后端引擎](../../../../../docs/runtime/how_to_change_backend.md)
|
@@ -0,0 +1,91 @@
|
||||
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", 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_trt_backend()
|
||||
option.set_trt_input_shape("image", [1, 3, 320, 320])
|
||||
option.set_trt_input_shape("scale_factor", [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_trt_backend()
|
||||
option.set_trt_input_shape("image", [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")
|
||||
|
||||
# 配置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")
|
||||
# 配置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)
|
||||
|
||||
# 预测图片检测结果
|
||||
im = cv2.imread(args.image)
|
||||
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)
|
||||
|
||||
# 预测结果可视化
|
||||
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")
|
Reference in New Issue
Block a user