onnx2tensorrt部署总结,按这个步骤,cmake不报错

reference :
https://blog.csdn.net/shanglianlm/article/details/88797529
https://zhuanlan.zhihu.com/p/380950900
https://zhuanlan.zhihu.com/p/366481434
https://blog.csdn.net/zong596568821xp/article/details/86077553
environment:
Anaconda3-5.3.0
cuda_10.2
cudnn-10.2-linux-x64-v8.1.1.33
TensorRT-7.1.3.4

creat conda environmen(not must install)

conda creat -n pytorch python=3.7
pip install --default-timeout=1000 torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -i https://pypi.tuna.tsinghua.edu.cn/simple --user

上面环境非必需
正式开始:
从这开始:-------------------------------------------------------

1.install tensorrt

down tensorrt

# chioce your tensorrt version from https://developer.nvidia.com/nvidia-tensorrt-download
#安装pycuda
pip install 'pycuda>=2017.1.1' -i https://pypi.tuna.tsinghua.edu.cn/simple --user
cd TensorRT-7.1.3.4/
   83  # TensorRT路径下
   84  sudo cp -r ./lib/* /usr/lib
   85  sudo cp -r ./include/* /usr/include
   86  cd python/
   88  pip install tensorrt-7.1.3.4-cp37-none-linux_x86_64.whl 
   89  cd ../uff/
 #  91  pip install uff-0.6.9-py2.py3-none-any.whl  # 下载太慢添加清华源
   92  pip install uff-0.6.9-py2.py3-none-any.whl  -i https://pypi.tuna.tsinghua.edu.cn/simple --user 
   93  cd ../graphsurgeon/
   94  pip install graphsurgeon-0.4.5-py2.py3-none-any.whl -i https://pypi.tuna.tsinghua.edu.cn/simple --user 

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/lt/softwares/TensorRT/TensorRT-7.1.3.4/lib
source ~/.bashrc

在这里插入图片描述
注意:导入 uff 的时候需要安装 tensorflow 模块,tensorflow 版本要与 cuda 版本对应,比如 cuda9 要对应 tensorflow1.12 及以下版本,以上版本需要 cuda10,具体参考官网

2.install onnx2tensorrt

缺少cmake,参照(1),缺少probuf参照(2),不缺直接跳(3) install onnx2tensorrt

(1)install cmake
下载cmake源码。地址
tar -xvf cmake-3.21.0.tar.gz
安装QT4,键入命令
sudo apt-get install qt4-default
sudo apt-get install libssl-dev
make -j8 && sudo make install
(2) install protobuf
选择分支,不要默认master,否则会报错,下载onnx2rensorrt的时候也是
Dont clone master choice protobuf >3.8 ,chioce other branches
在这里插入图片描述

#第一步
 git clone --recursive -b 3.16.x https://github.com/protocolbuffers/protobuf.git
 # -b 3.16.x  # git 指定分支,按照自己的版本下载,不要默认master 会报错,
 # onnx-tensorrt7.x的要求中明确写了 protobuf >=3.8
 # git clone  -b your_version  https://github.com/protocolbuffers/protobuf.git
# --recursive #  下载第三方模块,不然会报缺少第三方库,两种方式 
# 1.clone的时候同时下载第三方库 git clone --recursive
# 2.先clone 再下载第三方库 git submodule update --init --recursive 
# 因为网络等原因,第三方库下载可能失败,cmake编译会缺少第三方库,则可以用第二种方式
# 如下
or
 git clone  -b 3.16.x https://github.com/protocolbuffers/protobuf.git
 git submodule update --init --recursive
 #第二步
cd protobuf && ./autogen.sh
#报错:./autogen.sh: 37: ./autogen.sh: autoreconf: not found
#没有安装automake工具,执行下面即可
# sudo apt-get install autoconf automake libtool
mkdir install && ./configure
make -j8 && make check && sudo make install && sudo ldconfig

git submodule update --init --recursive #第三方库下载
(3) install onnx2tensorrt

 git clone -b 7.1 https://github.com/onnx/onnx-tensorrt.git  #  your tensrrt version  -b 
 # git submodule add -b 分支版本 分支地址 拉下来存放位置7.1,我的是7.1所以选7.1分支
 cd onnx2tensorrt
 mkdir build
cmake .. -DProtobuf_INCLUDE_DIRS=/home/lt/softwares/protobuf/src  -DTENSORRT_ROOT=/home/lt/softwares/TensorRT/TensorRT-7.1.3.4
# 如果报错 onnx-tensorrt/third_party/onnx does not contain a CMakeLIsts.txt file
# 下载第三方库即可
#git submodule update --init --recursive 
# 依旧第三方报错 [third_party/onnx/CMakeFiles/onnx_proto.dir/onnx/onnx_onnx2trt_onnx-ml.pb.cc.o] Error 1
# 注意 onnx 也有第三方库
# git submodule update --init --recursive 跟新第三方库
# 删除之前的 cmake 的文件,重新cmake 
rm -rf *
cmake .. -DProtobuf_INCLUDE_DIRS=/home/lt/softwares/protobuf/src  -DTENSORRT_ROOT=/home/lt/softwares/TensorRT/TensorRT-7.1.3.4
make -j8
sudo make install

安装成功如下所示Cmake

  1. 安装python库
    看版本 没有1)中内容,直接 python setup.py install即可,成功如下所示
    在这里插入图片描述

1)修改setup.py文件

找到第52行,添加-I/path/to/TensorRT-7.0.0.11/include。

52 SWIG_OPTS = [
53 ‘-I/home/lt/softwares/TensorRT/TensorRT-7.1.3.4/include’,
54 ‘-c++’,
55 ‘-modern’,
56 ‘-builtin’,
57 ]

2)安装

cd onnx-tensorrt
python setup.py install

若安装成功,则显示如下:

Using /xxx/3.6.5/lib/python3.6/site-packages
Finished processing dependencies for onnx-tensorrt==0.1.0

error:

缺少cmake,参照上面第2步(1),缺少probuf参照(2)
swig error: unable to execute 'swig': No such file or directory error: command 'swig' failed with exit status 1
下载swig :swig
or:wget http://prdownloads.sourceforge.net/swig/swig-4.0.2.tar.gz

./configure
make
make install

PCRE error:
SWIG:1: Error: PCRE regex support not enabled in this SWIG build.
error: command ‘swig’ failed with exit status 1
下载pcre: pcre-8.41

$ tar -zxvf pcre-8.41.tar.gz 
$ chmod -R 777 pcre-8.41
$ cd pcre-8.41/
$ ./configure
$ make
$ sudo make install

swig: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

#创建软链接到swig库
sudo ln -s /usr/local/lib/libpcre.so.1 /home/lt/softwares/swig-4.0.2/Lib

NvOnnxParser.h:222: Error: Syntax error in input(1)

# vim ./onnx-tensorrt/NvOnnxParser.h
# 添加如下内容
#define TENSORRTAPI

CMakeFiles/Makefile2:299: recipe for target ‘third_party/onnx/CMakeFiles/onnx_proto.dir/all’ failed
make[1]: *** [third_party/onnx/CMakeFiles/onnx_proto.dir/all] Error 2
Makefile:155: recipe for target ‘all’ failed
make: *** [all] Error 2

 git submodule update --init --recursive

onnx2trt -V
在这里插入图片描述

other

tensorflow:在这里插入图片描述pip install pillow==4.1.1 -i https://pypi.tuna.tsinghua.edu.cn/simple pip install tensorflow-gpu==2.4.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/

版本记录·:
swig-4.0.2.tar.gz
pcre-8.41.tar.gz
cmake-3.21.0.tar.gz
TensorRT-7.1.3.4.
reference :
https://blog.csdn.net/zong596568821xp/article/details/86077553
https://blog.csdn.net/shanglianlm/article/details/88797529:
https://zhuanlan.zhihu.com/p/380950900
https://zhuanlan.zhihu.com/p/366481434

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值