文章目录
参考方法github:
https://github.com/CoinCheung/BiSeNet/tree/master/tensorrt
- Export model to onnx;
- Build with source code;
- Convert onnx to tensorrt model.
创建conda的环境:
conda create -n vvv python=3.6
1. 安装ros
conda deactivate 退出conda ;
按照ros官网方法安装ros: http://wiki.ros.org/melodic/Installation/Ubuntu
问题1:
Ubuntu18.04安装ROS后初始化sudo rosdep init时出错pkg_resources.DistributionNotFound: The ‘rosdep==0.20.0‘
解决方法:更换默认的python
https://blog.csdn.net/moX980/article/details/110316752
问题2:ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
解决方法:切换手机热点。
2. 在conda环境中安装TensorRT 7.1
参考:https://zhuanlan.zhihu.com/p/181274475?utm_source=wechat_session
https://blog.csdn.net/zong596568821xp/article/details/86077553
-
建议按照官网方法做:
官网https://developer.nvidia.com/tensorrt下载对应版本的TensorRT 的tar文件。注意版本和cuda cudnn匹配。
解压:tar -xvzf TensorRT-7.1.3.4.Ubuntu-18.04.x86_64-gnu.cuda-10.2.cudnn8.0.tar.gz
定义TensorRT SDK所在的位置,方便后面的操作
export TRT_RELEASE=~/…/TensorRT-7.1.3.4
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:…/lib
环境配置,注意:
为了避免其它软件找不到tensorrt的库,建议把tensorrt的库和头文件添加到系统路经下:
https://blog.csdn.net/zong596568821xp/article/details/86077553
# TensorRT路径下
sudo cp -r ./lib/* /usr/lib
sudo cp -r ./include/* /usr/include
后续操作按照官网即可。
3. 卸载tensorRT
要使用未解压缩的文件卸载TensorRT,只需删除tar文件;
并重置LD_LIBRARY_PATH 还原为原始值。
4. Export model to onnx
https://github.com/CoinCheung/BiSeNet/tree/master/tensorrt
python -m ipdb ./tools/export_onnx.py --model bisenetv2 --weight-path ./res/model_final.pth --outpath ./model.onnx
修改输入的尺寸大小。
5. Build with source code
https://github.com/CoinCheung/BiSeNet/tree/master/tensorrt
mkdir -p tensorrt/build
cd tensorrt/build
cmake ..
make
问题1:
/usr/bin/ld: cannot find -lnvinfer
/usr/bin/ld: cannot find -lnvinfer_plugin
/usr/bin/ld: cannot find -lnvparsers
/usr/bin/ld: cannot find -lnvonnxparser
collect2: error: ld returned 1 exit status
解决方法:环境配置。为了避免其它软件找不到tensorrt的库,建议把tensorrt的库和头文件添加到系统路经下:
https://blog.csdn.net/zong596568821xp/article/details/86077553
# TensorRT路径下
sudo cp -r ./lib/* /usr/lib
sudo cp -r ./include/* /usr/include
6. Convert onnx to tensorrt model
https://github.com/CoinCheung/BiSeNet/tree/master/tensorrt
./segment compile /path/to/onnx.model /path/to/saved_model.trt
./segment compile /path/to/onnx.model /path/to/saved_model.trt --fp16
7. Infer with one single image
https://github.com/CoinCheung/BiSeNet/tree/master/tensorrt
./segment run /path/to/saved_model.trt /path/to/input/image.jpg /path/to/saved_img.jpg
8. Test speed
https://github.com/CoinCheung/BiSeNet/tree/master/tensorrt
./segment test /path/to/saved_model.trt
9. 封装到ros中
写图像读取节点1;
图像处理节点2;
通信节点3.