一 实验环境:
硬件及系统 : 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);

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

被折叠的 条评论
为什么被折叠?



