2022年2月7日 星期一

Install TensorRT on Ubuntu 20.04



It takes me a lot of time to get TensorRT working with Ubuntu 20.04 on my laptop.
There are some issues makes it even harder @@

1.With the default nVidia driver from Ubuntu 20.04, the laptop failed to resume after suspend (hibernate).
The solution is to reinstall older version. T
his lead cuda version limited to 10.2

sudo apt purge nvidia-* 
sudo apt autoremove
sudo apt install nvidia-driver-450-server

2.Ubuntu 20.04 default is python3.8 and TensorRT works with python3.6 

3.TensorRT doesn't support Ubuntu 20.04 with cuda 10.2

The solution is to use python virtualenv to install TensorRT  

sudo apt install python3.6-venv

mkdir venv/
cd venv

### Create virtual environment in path venv/tensorrt

python3.6 -m venv tensorrt

source tensorrt/bin/activate

pip install --upgrade pip

python3 -m pip install numpy onnx

### Download & extract TensorRT-7.2.3.4.Ubuntu-18.04.x86_64-gnu.cuda-10.2.cudnn8.1.tar.gz

cd Downloads/

sudo cp -a TensorRT-7.2.3.4 /usr/local/

export LD_LIBRARY_PATH=/usr/local/TensorRT-7.2.3.4/lib

cd TensorRT-7.2.3.4/python/

python3 -m pip install tensorrt-7.2.3.4-cp36-none-linux_x86_64.whl

cd ../uff

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

which convert-to-uff

cd ../graphsurgeon/

python3 -m pip install graphsurgeon-0.4.5-py2.py3-none-any.whl

cd ../onnx_graphsurgeon/

python3 -m pip install onnx_graphsurgeon-0.2.6-py2.py3-none-any.whl

cd ../..

### Download libcudnn8_8.2.1.32-1+cuda10.2_amd64.deb & libcudnn8-dev_8.2.1.32-1+cuda10.2_amd64.deb

sudo dpkg -i ./libcudnn8_8.2.1.32-1+cuda10.2_amd64.deb
sudo dpkg -i ./libcudnn8-dev_8.2.1.32-1+cuda10.2_amd64.deb

pip3 install torch
pip3 install torchvision
pip3 install matplotlib

pip3 install --global-option=build_ext --global-option="-I/usr/local/cuda-10.2/targets/x86_64-linux/include/" --global-option="-L/usr/local/cuda-10.2/targets/x86_64-linux/lib/" pycuda

pip3 install opencv-python
pip3 install albumentations==0.5.2



4.Using the tensorrt venv

cd venv
source tensorrt/bin/activate