github地址:https://github.com/onnx/onnx-tensorrt/tree/master
安装onnx-tensorrt
最新版似乎没有安装的教程,但是可以根据旧版来安装。
先把旧版完整的安装过程列出来:
git clone --recursive https://github.com/onnx/onnx-tensorrt.git
mkdir build
cd build
cmake .. -DTENSORRT_ROOT=<tensorrt_install_dir>
OR
cmake .. -DTENSORRT_ROOT=<tensorrt_install_dir> -DGPU_ARCHS="61"
make -j8
sudo make install
首先,clone代码可以使用:
git clone --recurse-submodules https://github.com/onnx/onnx-tensorrt.git
在安装前,要确保protobuf的版本满足条件,不然后续安装会花费大量时间(多么痛的领悟)。
安装protobuf
因为我安装了anaconda,自带protoc,网上没找到合适的教程,就把它直接卸载了:
which protoc
rm /path/to/protoc
然后再查看protoc版本,结果显示3.0.0,应该是ubuntu系统自带的,也顺带卸载。
接着就要去github上下载:https://github.com/protocolbuffers/protobuf/releases
解压:
tar -xvf protobuf-all-3.11.4.tar.gz
- 安装:
cd protobuf-3.11.4
./configure
make
make check
make install
- 配置环境变量:
gedit ~/.bashrc
添加:
export PATH=$PATH:/usr/local/bin/
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
保存执行
source ~/.bashrc
- 配置动态链接库路径
sudo vi /etc/ld.so.conf
添加:
include /usr/local/protobuf/lib
保存并退出。
共享:
su root
ldconfig
查看protoc版本:
protoc --version
完成。
一些问题
尽量使用下面的cmake方式(加上算力会出一些问题,不知道会不会影响)
cmake .. -DTENSORRT_ROOT=<tensorrt_install_dir>
执行make时出错了,如:fatal error: google/protobuf/port_def.inc: No such file or directory
这应该是protoc出问题了,于是我又看了下cmake的结果,果然发现中间出了错误:
Protobuf compiler version 3.11.4 doesn't match library version 3.0.0
...
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;pthread (found version "3.0.0")
protoc的编译器和库版本不匹配,这就是protoc的动态链接库有问题。