https://developer.nvidia.com/nvidia-tensorrt-8x-download
`
tar -zxvf TensorRT-8.4.1.5.Linux.x86_64-gnu.cuda-10.2.cudnn8.4.tar.gz
`
放在主目录下面
sudo gedit ~/.bashrc
export LD_LIBRARY_PATH=/home/xuanxi/TensorRT-8.4.1.5/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/home/xuanxi/TensorRT-8.4.1.5/lib::$LIBRARY_PATH
source ~/.bashrc
cd ./TensorRT-8.4.1.5/python
python文件夹里面有很多版本,使用pip安装自己对应的python版本
进入虚拟环境(!!!)
source activate torch1.7
pip install tensorrt-8.4.1.5-cp37-none-linux_x86_64.whl
(torch1.7) xuanxi@xuanxi-MS-7C02:~/TensorRT-8.4.1.5/python$ python
Python 3.7.9 (default, Aug 31 2020, 12:42:55)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorrt
>>> tensorrt.__version__
可以顺便安装其他两个包
1)安装 uff 包
cd ../uff # 切换到 uff 文件夹
pip install uff-0.6.9-py2.py3-none-any.whl
测试是否安装成功:
which convert-to-uff # 会输出安装路径
2)安装 graphsurgen 包
cd ../graphsurgeon # 切换到 graphsurgeon 文件夹
pip install graphsurgeon-0.3.2-py2.py3-none-any.whl
python -m pip install colored polygraphy --extra-index-url https://pypi.ngc.nvidia.com
polygraphy run model_4.onnx --onnxrt --val-range [0,1] --save-inputs onnx_inputs.json --save-outputs onnx_outputs.json
polygraphy run rvm_mobilenetv3_fp32_sim_modified.engine --model-type engine --trt --load-inputs onnx_inputs.json --load-outputs onnx_outputs.json --rtol 1e-3 --atol 1e-3
polygraphy run model_4.onnx
–onnxrt --trt
–workspace 100000000
–save-engine=model_FP32_MarkAll.plan
–atol 1e-3 --rtol 1e-3
–verbose
–onnx-outputs mark all
–trt-outputs mark all
–trt-min-shapes ‘x:0:[1,1,28,28]’
–trt-opt-shapes ‘x:0:[4,1,28,28]’
–trt-max-shapes ‘x:0:[1,28,28]’
–input-shapes ‘x:0:[1,80,300]’
> result-run-FP32-MarkAll.txt
报错:libnvinfer.so.8: cannot open shared object file: No such file or directory
解压后进入TensorRT根目录:
(1)环境变量
sudo gedit ~/.bashrc
在文件末尾添加一行代码:
export LD_LIBRARY_PATH=/opt/TensorRT-8.4.2.4/lib:$LD_LIBRARY_PATH
关闭保存
source ~/.bashrc
(2)复制文件到系统路径(!!)
把TensorRT根目录中的/lib/下面的文件复制到 /usr/lib/下,
把TensorRT根目录中的/include/下面的文件复制到 /usr/include/下
xuanxi@xuanxi-MS-7C02:~/TensorRT-8.4.2.4$ sudo cp -r lib/* /usr/lib/
xuanxi@xuanxi-MS-7C02:~/TensorRT-8.4.2.4$ sudo cp -r include/* /usr/include/