python 下调用 TensorRT onnx 的一种实现 (验证 retinaface)

该博客介绍了在jetson nano jetpack 4.4.1系统上,使用cuda 10.2、opencv4.5、tensorRT 7.1的实验环境。目标是为tensorrt_retinaface工程增加Python调用检测支持,学习C++库包装Python模块的方法。过程包括C++模块包装、Python模块打包和验证。

一 实验环境:

 硬件及系统 : jetson nano jetpack 4.4.1 

深度学习库版本: cuda 10.2  opencv4.5、 tensorRT 7.1 

二 目标:

retinaface 据说是 准确 率和速度最快的 人脸检测和 landmark 框架!tensorRT 的版本可以到 4ms.

可以看看大牛的文章:

https://juejin.im/post/6844903967059771399

模型跑起来发现调用很不方便, 习惯了用jupyter 快速搭建demo, 这个是听起来如此之牛的模型竟然 只有 C++的。

所以打算给 tensorrt_retinaface 工程增加 python 调用 检测支持,

同时学习 C++ 库包装 python 模块的方法, 实现 opencv 在 python + c++ 混合编程 !

github 地址:

https://github.com/walletiger/tensorrt_retinaface_with_python

后记: 验证完发现了 onnx-tensorRT 有 python bindings 。。 能否把retinaface_mbv2_sim.onnx 跑起来 ?学会了再分享

# readme 
# tensorrt_retinaface_with_python
just add python bindings for tensorrt_retinaface detect frame works (support onnx to tensorRT modules)

# tensorrt_retinaface_with_python
just add python bindings for tensorrt_retinaface detect frame works (support onnx to tensorRT modules)

# TensorRT ONNX with python bindings 

clone from https://github.com/wuchaodzxx/tensorrt_retinaface

I add python bindings for python3 support for tensortRT ONNX (+  opencv4)

#how to run:
#1 ./build_all.sh 
#2 cp build/libtensorrt_engine_lib.so  /usr/local/lib/
#3 cd python && python3 setup.py install 
# you must have cuda , tensorRT , opencv4.x , python-boost installed 
#4 convert onnx models to tensorRT
onnx2trt models/retinaface_mbv2_sim.onnx -o models/retinaface.trt
#5 test 
cd python &&  python3 test.py 


#details:
tensorRT wrapper : tensorrt_engine_wrap.cc
python Modules   : python/trt_engine_retinaface_module.cpp python/setup.py 

#python Modules   :
references : 
https://github.com/PierreFritsch/OpenCV-Python-C-Module-for-Image-Processing/
https://github.com/Algomorph/pyboostcvconverter

OpenCV-Python-C-Module-for-Image-Processing project is simple but does not work for my opencv4 env . 
pyboostcvconverter is a little complicated.

i extract pyboost_cv4_converter.cpp from pyboostcvconverter , and combine it to OpenCV-Python-C-Module-for-Image-Processing 

三 过程

3.1 C++ 模块包装

提供三个接口方便移植

代码在

include/tensorrt_engine_wrap.h

src/tensorrt_engine_wrap.cc 

void * trt_engine_retinaface_create(const char * engine_path);
const char * trt_engine_retinaface_detect(void *h_engine, cv::Mat &img);
void trt_engine_retinaface_destroy(void *h_engine);

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

walletiger

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值