本文节介绍 PP-TSM 模型如何转化为 ONNX 模型,并基于 ONNX 引擎预测。
1:环境准备
- 安装 Paddle2ONNX
python -m pip install paddle2onnx
- 安装 ONNXRuntime
# 建议安装 1.9.0 版本,可根据环境更换版本号
python -m pip install onnxruntime==1.9.0
2:模型转换
paddle2onnx \
--model_dir=output/ppTSMv2_inference \
--model_filename=ppTSMv2.pdmodel \
--params_filename=ppTSMv2.pdiparams \
--save_file=output/ppTSMv2_inference/ppTSMv2.onnx \
--opset_version=10 \
--enable_onnx_checker=True
3:模型预测
onnx 推理
python deploy/paddle2onnx/predict_onnx.py \
--input_file data/example.avi \
--config configs/recognition/pptsm/v2/pptsm_lcnet_ucf101_8frames_uniform.yaml \
--onnx_file=output/ppTSMv2_inference/ppTSMv2.onnx
paddle 推理
python tools/predict.py --input_file data/example.avi \
--config configs/recognition/pptsm/v2/pptsm_lcnet_ucf101_8frames_uniform.yaml \
--model_file output/ppTSMv2_inference/ppTSMv2.pdmodel \
--params_file output/ppTSMv2_inference/ppTSMv2.pdiparams \
--use_gpu=True \
--use_tensorrt=False
可以看出onnx结果与Paddle 推理结果完全一致。
参考链接
1:PaddleVideo/deploy/paddle2onnx at develop · PaddlePaddle/PaddleVideo · GitHubAwesome video understanding toolkits based on PaddlePaddle. It supports video data annotation tools, lightweight RGB and skeleton based action recognition model, practical applications for video tagging and sport action detection. - PaddleVideo/deploy/paddle2onnx at develop · PaddlePaddle/PaddleVideohttps://github.com/PaddlePaddle/PaddleVideo/tree/develop/deploy/paddle2onnx