onnx-tensorrt安装

一、参考资料

onnx-tensorrt官方仓库
onnx-tensorrt安装

二、重要说明

  • onnx-tensorrt与tensorRT版本对齐;
  • onnx-tensorrt与protobuf版本对齐;
    onnx-tensorrt安装_第1张图片

三、准备工作

1. 安装Protobuf

1. 下载地址
[Protocol Buffers v3.19.1](https://github.com/protocolbuffers/protobuf/releases)

2. 解压文件
tar -zxvf protobuf-all-3.12.3.tar.gz

3. 更改安装路径
cd protobuf-3.12.3/
./autogen.sh
./configure --prefix=/home/yichao/360Downloads/protobuf

4. 编译,安装
make -j 12
make check
make install

5. 设置环境变量
export PATH="/home/yichao/360Downloads/protobuf/bin:$PATH"

source ~/.bashrc
make[2]: Leaving directory '/home/yichao/360Downloads/protobuf-3.19.1/src'
make  check-TESTS
make[2]: Entering directory '/home/yichao/360Downloads/protobuf-3.19.1/src'
make[3]: Entering directory '/home/yichao/360Downloads/protobuf-3.19.1/src'
PASS: protobuf-test
PASS: protobuf-lazy-descriptor-test
PASS: protobuf-lite-test
PASS: google/protobuf/compiler/zip_output_unittest.sh
PASS: google/protobuf/io/gzip_stream_unittest.sh
PASS: protobuf-lite-arena-test
PASS: no-warning-test
============================================================================
Testsuite summary for Protocol Buffers 3.19.1
============================================================================
# TOTAL: 7
# PASS:  7
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
make[3]: Leaving directory '/home/yichao/360Downloads/protobuf-3.19.1/src'
make[2]: Leaving directory '/home/yichao/360Downloads/protobuf-3.19.1/src'
make[1]: Leaving directory '/home/yichao/360Downloads/protobuf-3.19.1/src'

2. 安装tensorRT

参考博客 【Ubuntu版】TensorRT安装教程

3. 安装onnx

onnx v1.8.1

git clone https://github.com/onnx/onnx.git
cd onnx

# 查看版本
git tag

# 切换分支
git checkout v1.8.1

git submodule update --init --recursive
python setup.py install

# 验证是否安装成功
python -c "import onnx"

四、关键步骤

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

举例:

# 下载
git clone --recursive https://github.com/onnx/onnx-tensorrt.git

# 查看分支
git tag

# 切换分支,与tensorRT版本一致
git checkout release/8.0

mkdir build
cd build

cmake .. -DTENSORRT_ROOT=/home/yichao/360Downloads/TensorRT-8.0.1.6 -DGPU_ARCHS="75"

make -j6
sudo make install

五、可能出现的问题

  • 缺少protoc

    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:301 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:292 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:292 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:301 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:310 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:310 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:292 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:292 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:301 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:310 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:301 (relative_protobuf_generate_cpp)
    
    
    CMake Error at third_party/onnx/CMakeLists.txt:277 (add_custom_command):
      Error evaluating generator expression:
    
        $<TARGET_FILE:protobuf::protoc>
    
      No target "protobuf::protoc"
    Call Stack (most recent call first):
      third_party/onnx/CMakeLists.txt:310 (relative_protobuf_generate_cpp)
    
    错误原因:
    
    解决办法:
    下载protobuf,重新安装protobuf
    

    附录:系统各种环境变量

    #(动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib/
    #(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径
    export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib/
    #执行程序搜索路径
    export PATH=$PATH:/usr/local/protobuf/bin/
    #c程序头文件搜索路径
    export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/protobuf/include/
    #c++程序头文件搜索路径
    export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/protobuf/include/
    #pkg-config 路径
    export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/
    
  • 编译onnx失败

    File "setup.py", line 211, in run
        subprocess.check_call(build_args)
      File "/home/yichao/miniconda3/envs/tensorRT-efficientdet/lib/python3.7/subprocess.py", line 363, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['/usr/bin/cmake', '--build', '.', '--', '-j', '6']' returned non-zero exit status 2.
    

你可能感兴趣的:(编程工具,TensorRT,ONNX,onnx-tensorrt)