TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)

1 Win7+CUDA9.0+TensorRT安装

1-1 下载对应TensorRT版本

https://developer.nvidia.com/nvidia-tensorrt-5x-download

这里我们选择 TensorRT 5.0 GA For Windows
在这里插入图片描述

1-2 解压 TensorRT

在这里插入图片描述

1-3 配置环境变量

将TensorRT解压位置\lib 加入系统环境变量
在这里插入图片描述
将TensorRT解压位置\lib下的dll文件复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin目录下
在这里插入图片描述

1-4 测试示例代码

用VS2017打开sampleMNIST示例(D:\TensorRT-5.0.4.3\samples\sampleMNIST)
a. 将D:\TensorRT-5.0.4.3\lib加入 VC++目录–>可执行文件目录
在这里插入图片描述
b. 将D:\TensorRT-5.0.4.3\include加入C/C++ --> 常规 --> 附加包含目录
在这里插入图片描述
c.将D:\TensorRT-5.0.4.3\lib加入 VC++目录–>库目录
将nvinfer.lib、nvinfer_plugin.lib、nvonnxparser.lib和nvparsers.lib加入链接器–>输入–>附加依赖项

在这里插入图片描述
编译后运行得到结果
在这里插入图片描述

2 Ubuntu-16.04+CUDA9.0+TensorRT-5.0安装

2-1下载

https://developer.nvidia.com/nvidia-tensorrt-5x-download

2-2 解压

tar -zxvf TensorRT-5.0.2.6.Ubuntu-16.04.4.x86_64-gnu.cuda-9.0.cudnn7.3.tar.gz
cd TensorRT-5.0.2.6/

2-3 添加环境变量

vim ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/liumin/software/TensorRT-5.0.2.6/lib
source ~/.bashrc

2-4 安装 Python TensorRT wheel 文件

cd python/
pip install tensorrt-5.0.2.6-py2.py3-none-any.whl

2-5 安装 Python UFF wheel 文件

cd ../uff/
pip install uff-0.5.5-py2.py3-none-any.whl

2-6 安装 Python graphsurgeon wheel 文件

cd ../graphsurgeon/
pip install graphsurgeon-0.3.2-py2.py3-none-any.whl

2-7 测试

cd samples/sampleMNIST
make
cd ../../bin
./sample_mnist

输出:

[09/03/2020-09:21:44] [I] Building and running a GPU inference engine for MNIST
[09/03/2020-09:21:48] [I] [TRT] Detected 1 inputs and 1 output network tensors.
[09/03/2020-09:21:48] [W] [TRT] Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles
[09/03/2020-09:21:48] [I] Input:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@+  #@@@@@@
@@@@@@@@@@@@@@@@@*   #@@@@@@
@@@@@@@@@@@@@@@@@=   #@@@@@@
@@@@@@@@@@@@@@@@#  .%@@@@@@@
@@@@@@@@@@@@@@@#.  *@@@@@@@@
@@@@@@@@@@@@@@@-  :@@@@@@@@@
@@@@@@@@@@@@@@@   #@@@@@@@@@
@@@@@@@@@@@@@%.  =@@@@@@@@@@
@@@@@@@@@@@@@+  :@@@@@@@@@@@
@@@@@@@@@@@@*  :%@@@@@@@@@@@
@@@@@@@@@@@%   -@@@@@@@@@@@@
@@@@@@@@@@@=   %@@@@@@@@@@@@
@@@@@@@@@@#.  -@@@@@@@@@@@@@
@@@@@@@@@@   :@@@@@@@@@@@@@@
@@@@@@@@@@   *@@@@@@@@@@@@@@
@@@@@@@@@-   %@@@@@@@@@@@@@@
@@@@@@@@#.  =@@@@@@@@@@@@@@@
@@@@@@@@#  .@@@@@@@@@@@@@@@@
@@@@@@@@#  .@@@@@@@@@@@@@@@@
@@@@@@@@%: .@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@

[09/03/2020-09:21:48] [I] Output:
0: 
1: **********
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 

&&&& PASSED TensorRT.sample_mnist # ./sample_mnist

常见报错:
1 运行示例时,提示找不到 MNIST数据

[xxx@localhost bin]$ ./sample_mnist
&&&& RUNNING TensorRT.sample_mnist # ./sample_mnist
[09/03/2020-09:15:29] [I] Building and running a GPU inference engine for MNIST
[09/03/2020-09:15:34] [I] [TRT] Detected 1 inputs and 1 output network tensors.
[09/03/2020-09:15:34] [W] [TRT] Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles
Could not find 2.pgm in data directories:
	data/mnist/
	data/samples/mnist/
&&&& FAILED

这是因为在TensorRT 7.x以后需要手动下载MNIST数据
进入data/mnist目录,运行

python download_pgms.py

2 .加载 libnvinfer.so.7报错

[xxx@localhost bin]$ ./sample_mnist
./sample_mnist: error while loading shared libraries: libnvinfer.so.7: cannot open shared object file: No such file or directory

参考资料
1 TensorRT Installation Guide https://docs.nvidia.com/deeplearning/sdk/tensorrt-install-guide/index.html
2 TensorRT Documentation https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/c_api/index.html
3 Best Practices For TensorRT Performance https://docs.nvidia.com/deeplearning/sdk/tensorrt-best-practices/index.html
4 TensorRT Developer Guide https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html
5 TensorRT API https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/index.html
6 Samples Support Guide https://docs.nvidia.com/deeplearning/sdk/tensorrt-sample-support-guide/index.html

  • 4
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值