English | 简体中文
在部署前,需确认以下两个步骤
-
- 软硬件环境满足要求,参考FastDeploy环境要求
-
- 根据开发环境,下载预编译部署库和samples代码,参考FastDeploy预编译库
本目录下提供pptinypose_infer.py
快速完成PP-TinyPose在CPU/GPU,以及GPU上通过TensorRT加速部署的单图单人关键点检测
示例。执行如下脚本即可完成
注意: PP-Tinypose单模型目前只支持单图单人关键点检测,因此输入的图片应只包含一个人或者进行过裁剪的图像。多人关键点检测请参考PP-TinyPose Pipeline
#下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/keypointdetection/tiny_pose/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/hrnet_demo.jpg
# CPU推理
python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device cpu
# GPU推理
python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device gpu
# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device gpu --use_trt True
# 昆仑芯XPU推理
python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device kunlunxin
运行完成可视化结果如下图所示
fd.vision.keypointdetection.PPTinyPose(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
PP-TinyPose模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明模型导出
参数
- model_file(str): 模型文件路径
- params_file(str): 参数文件路径
- config_file(str): 推理部署配置文件
- runtime_option(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
- model_format(ModelFormat): 模型格式,默认为Paddle格式
PPTinyPose.predict(input_image)模型预测结口,输入图像直接输出检测结果。
参数
- input_image(np.ndarray): 输入数据,注意需为HWC,BGR格式
返回
返回
fastdeploy.vision.KeyPointDetectionResult
结构体,结构体说明参考文档视觉模型预测结果
用户可按照自己的实际需求,修改下列后处理参数,从而影响最终的推理和部署效果
- use_dark(bool): 是否使用DARK进行后处理参考论文