下载TensorRT
官网https://developer.nvidia.com/tensorrt下载对应版本的TensorRT(示例为 cuda 10.0 cudnn 7.6),需注册账号、填写问卷调查方可下载。
设置环境变量
TensorRT-7.0.0.11.Windows10.x86_64.cuda-10.0.cudnn7.6.zip解压至本地,将
xxx\TensorRT-7.0.0.11\lib 添加至环境变量
安装uff和graphsurgeon
xxx\TensorRT-7.0.0.11\下有uff和graphsurgeon,分别安装两个文件夹下的安装包 (激活对应的虚拟环境,比如我是python36):
>>pip install .\uff-0.6.5-py2.py3-none-any.whl
>>pip install .\graphsurgeon-0.4.1-py2.py3-none-any.whl
测试
用vs 2015打开TensorRT-7.0.0.11\samples\sampleMNIST下的sample_mnist.sln,生成项目,在
在TensorRT-7.0.0.11\bin下会新生成sample_mnist.exe
命令行切换进目录TensorRT-7.0.0.11\data\mnist,运行:
>python download_pgms.py
下载所需数据,
然后切换到TensorRT-7.0.0.11\bin目录,运行生成的sample_mnist.exe即可(注意指定一下--datadir,在 根目录下data/mnist,不然可能找不到数据)
(python36) PS D:\xx\TensorRT\TensorRT-7.0.0.11\bin> .\sample_mnist.exe --datadir D:\xx\TensorRT\TensorRT-7.0.0.11\data\mnist
&&&& RUNNING TensorRT.sample_mnist # D:\Software\xx\TensorRT\TensorRT-7.0.0.11\bin\sample_mnist.exe --datadir D:\xx\TensorRT\TensorRT-7.0.0.11\data\mnist
[03/10/2020-16:37:34] [I] Building and running a GPU inference engine for MNIST
[03/10/2020-16:37:36] [W] [TRT] TensorRT was linked against cuDNN 7.6.3 but loaded cuDNN 7.4.2
[03/10/2020-16:37:36] [I] [TRT] Detected 1 inputs and 1 output network tensors.
[03/10/2020-16:37:36] [W] [TRT] TensorRT was linked against cuDNN 7.6.3 but loaded cuDNN 7.4.2
[03/10/2020-16:37:36] [W] [TRT] TensorRT was linked against cuDNN 7.6.3 but loaded cuDNN 7.4.2
[03/10/2020-16:37:36] [W] [TRT] Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles
[03/10/2020-16:37:36] [I] Input:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@%%+ -@@@@@@@
@@@@@@@@@%=.. -@@@@@@
@@@@@@@@@: #@@@@@
@@@@@@@@@+ ====: #@@@@@
@@@@@@@@@@%%%@@@@@. -@@@@@@
@@@@@@@@@@@@@@@@@* =@@@@@@
@@@@@@@@@@@@@@@@*: @@@@@@@
@@@@@@@@@@@@@@*. .@@@@@@@
@@@@@@@@@%+::: +%@@@@@@@
@@@@@@@@%. -@@@@@@@@@
@@@@@@@@%. *@@@@@@@@
@@@@@@@@@%+#%%%%= *@@@@@@@@
@@@@@@@@@@@@@@@@@ *@@@@@@@@
@@@@@@@@@@@@@@@@* *@@@@@@@@
@@@@@@@*@@@@@@@* *@@@@@@@@
@@@@@#: %@@@@@* #@@@@@@@@
@@@@@. =====: :*@@@@@@@@@
@@@@@. -@@@@@@@@@@@
@@@@@#- ..=%@@@@@@@@@@@@
@@@@@@@+ -+%@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[03/10/2020-16:37:36] [I] Output:
0:
1:
2:
3: **********
4:
5:
6:
7:
8:
9:
可能的bug:
报错信息 :The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".
原因:Visual Studio 2015 编辑错误,是缺少了v141组件
方法:
项目-->属性--->常规-->平台工具集--->选择 Visual Studio 2015 (v140),或者Visual Studio 2015 - Windows XP (v140_xp)确定,重新生成。