tensorrt 从0开始搭建部署环境

pip installization

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.7 get-pip.py

…pyhton3.7 -m pip xxx

cuda installization

cuda url

cudnn installization

cudnn url

  • 方式1
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin 

sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update


sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version}
sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version}
  • 方式2
tar -xvf cudnn-10.1-linux-x64-v8.0.5.39.tar

$ sudo cp cuda/include/cudnn*.h /usr/local/cuda/include 
$ sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64 
$ sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

tensorrt installization

手动官网下载: https://developer.nvidia.com/nvidia-tensorrt-7x-download

tar xvf TensorRT-7.2.1.6.Ubuntu-18.04.x86_64-gnu.cuda-11.1.cudnn8.0.tar.gz


cd python
python3.6 -m pip install tensorrt-7.2.1.6-cp37-none-linux_x86_64.whl

cd uff
python3.6 -m pip install uff-0.6.9-py2.py3-none-any.whl

python3.6
import tensorrt

如果python版本出错,则更新下pip如:
python3.6 -m pip install --upgrade pip

torch2rt installization

sudo apt-get install libprotobuf* protobuf-compiler ninja-build
​
## 适用于 TRT7
git clone https://github.com/NVIDIA-AI-IOT/torch2trt
​
## 适用于 TRT8
git clone -b support_trt_8 https://gitee.com/jeremyjj/torch2trt-trt8.git
​
cd torch2trt
sudo python3.6 setup.py install

测试是否成功安装torch2rt

import torch 
import torchvision
from torch2trt import torch2trt
​
batch_size = 1
## export resnet50  input: batchsize 3 224 224
net = torchvision.models.resnet50(pretrained=True).cuda()
​
input_data = torch.rand((batch_size, 3, 224, 224), dtype=torch.float).cuda()## convert to TensorRT int8 model
model_trt_int8 = torch2trt(net.eval(), [input_data], max_batch_size=batch_size, int8_mode=True)
​
out_trt = model_trt_int8(input_data)

你可能感兴趣的:(pytorch,学习,部署,python,linux,ubuntu)