YOLOv5—RTX3080 conda环境配置cuda11.1、cudnn8.0.5、pytorch1.8.0、tensorrt7.2.2.3、opencv4.4.0、deepstream5.1.0

目录

  • 前言
    • 1.X86版本的Anaconda的安装
      • 1.1 安装anaconda
      • 1.2 创建虚拟环境
    • 2.更新驱动
    • 3.安装cuda11.1和cudnn8.0.5
      • 3.1安装cuda11.1
      • 3.2安装cudnn8.0.5
    • 4.安装yolov5环境支持
    • 5.安装torch1.8.0与torchvision0.9.0
    • 6.安装TensorRT 7.2.2.3
    • 7.安装OPENCV 4.4.0
    • 8.安装DeepStream5.1.0

前言

所需安装包资源
链接:https://pan.baidu.com/s/1FaT72bBS8fwp7vO3z6tH5Q
提取码:d6tv

1.X86版本的Anaconda的安装

1.1 安装anaconda

(1)下载页面链接:https://www.anaconda.com/products/individual
根据系统信息选择相应的安装包,如下图所示:
YOLOv5—RTX3080 conda环境配置cuda11.1、cudnn8.0.5、pytorch1.8.0、tensorrt7.2.2.3、opencv4.4.0、deepstream5.1.0_第1张图片
(2)安装步骤
1)cd 文件下载目录

2)执行命令:bash Anaconda3-2020.11-Linux-x86_64.sh
安装过程中:
<1> 阅读注册信息,回车继续
在这里插入图片描述
<2> 同意注册信息,输入:“yes”,回车继续
在这里插入图片描述
<3> 自定义安装路径,回车继续
!!!若是自定义的安装路径,需要将自定义文件夹下的:
(1) bin/pip (2) bin/pip3 (3) bin/conda (4) bin/conda_env
4个文件第一行修改为:#!自定义安装路径/bin/python

<4> 加入环境变量的提示信息,输入:“yes”,回车继续
在这里插入图片描述

1.2 创建虚拟环境

创建新的虚拟环境,虚拟环境名称:yolov5。由于使用python3.8,所以在创建虚拟环境时,拉入3.8的python。
执行命令:conda create -n yolov5 python=3.8
安装过程中:
出现:Proceed ([y]/n)?
输入:“y”,回车继续

等待安装完成,若出现如下内容,则说明环境创建成功:

# To activate this environment, use
#     $ conda activate yolov5
# To deactivate an active environment, use
#     $ conda deactivate

查看环境命令:conda env list
!!!若希望conda的基本环境在启动时不被激活,将auto_activate_base参数设置为false:
(1)执行命令:conda config --set auto_activate_base false
(2)执行命令:sudo reboot
(3)输入密码后生效

2.更新驱动

2.1 删除cuda
依次执行以下命令:
(1)sudo apt-get remove cuda
(2)sudo apt --purge remove "*cublas*" "cuda*"
(3)sudo apt-get autoclean
(4)sudo apt-get remove cuda*

2.2 更新驱动
依次执行以下命令:
(1)解决依赖项:sudo apt-get install –y
(2)删除无关依赖包:sudo apt-get autoremove
(3)推荐安装: sudo ubuntu-drivers autoinstall

3.安装cuda11.1和cudnn8.0.5

3.1安装cuda11.1

(1)wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
(2)sudo sh cuda_11.1.0_455.23.05_linux.run

设置环境变量
1>sudo vim ~/.bashrc
2>添加以下两行内容
(1)export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
(2)export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

使环境变量生效,执行命令: source ~/.bashrc
执行命令: nvcc -V

3.2安装cudnn8.0.5

(1)进入英伟达官网,根据系统信息(本机为ubuntu18.04)下载如下所需的3个deb文件:
YOLOv5—RTX3080 conda环境配置cuda11.1、cudnn8.0.5、pytorch1.8.0、tensorrt7.2.2.3、opencv4.4.0、deepstream5.1.0_第2张图片

(1)cd 文件下载目录
(2)依次执行以下命令:

sudo dpkg -i libcudnn8_8.0.5.39-1+cuda11.1_amd64.deb
sudo dpkg -i libcudnn8-dev_8.0.5.39-1+cuda11.1_amd64.deb
sudo dpkg -i libcudnn8-samples_8.0.5.39-1+cuda11.1_amd64.deb

查看CUDNN: cat /usr/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

4.安装yolov5环境支持

进入创建的指定环境命令:conda activate yolov5

以下为yolov5的requirements(此处未安装torch和torchvision):

# pip install -r requirements.txt
# base ----------------------------------------
cython
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
Pillow
PyYAML>=5.3
scipy>=1.4.1
tensorboard>=2.2
# torch>=1.7.0
# torchvision>=0.8.1
tqdm>=4.41.0

# logging -------------------------------------
# wandb

# plotting ------------------------------------
seaborn>=0.11.0
pandas

# export --------------------------------------
# coremltools==4.0
# onnx>=1.8.0
# scikit-learn==0.19.2  # for coreml quantization

# extras --------------------------------------
thop  # FLOPS computation
pycocotools>=2.0  # COCO mAP

执行命令:
(1)cd requiements.txt的目录:
(2)最好进入新建虚拟环境的bin目录下,执行命令:pip install -r requiements.txt
提示:若下载速度太慢,可使用以下任一镜像源下载,执行如下命令:
清华源:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
阿里源:
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
中科大源:
pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple/

5.安装torch1.8.0与torchvision0.9.0

(1)cd 文件下载目录
(2)pip install torch-1.8.0+cu111-cp38-cp38-linux_x86_64.whl torchvision==0.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
(3) pip install torchaudio==0.8.0 -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

注:按照以下操作修改torch对应的激活函数
(1)输入:python
(2)输入:import torch

    输入:print(torch.__path__)
    显示torch的路径

    输入:torch.cuda.is_available()
    出现True,说明cuda正确使用

(2)cd 虚拟环境路径

(3) cd /lib/python3.8/site-packages/torch/nn/modules

(4)sudo vim activation.py

(5)修改“,self.inplace”
即把return F.hardswish(input, self.inplace)修改为return F.hardswish(input)

6.安装TensorRT 7.2.2.3

官网安装教程

1.安装pycuda,即可使用python接口的tensorrt

pip install pycuda

2.下载tensorrt
tensorrt下载链接:
https://developer.nvidia.com/nvidia-tensorrt-download
根据自己的系统版本和CUDA版本,选择安装包,如图:
YOLOv5—RTX3080 conda环境配置cuda11.1、cudnn8.0.5、pytorch1.8.0、tensorrt7.2.2.3、opencv4.4.0、deepstream5.1.0_第3张图片
解压下载的文件,本文使用TensorRT-7.2.2.3

tar -xzvf TensorRT-7.2.2.3.Ubuntu-18.04.x86_64-gnu.cuda-11.1.cudnn8.1.tar.gz

设置环境变量:
(1)vim ~/.bashrc
(2)将解压后得到TensorRT-7.2.2.3的文件夹的lib绝对路径添加到环境变量中
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/TensorRT-7.2.2.3/lib
(3)source ~/.bashrc

3.安装tensorrt
根据自己的python3.x(cp3x)安装对应的whl文件

cd /data/TensorRT-7.2.2.3/python
pip install tensorrt-7.2.2.3-cp38-none-linux_x86_64.whl

安装graphsurgeon,支持自定义结构

 cd /data/TensorRT-7.2.2.3/graphsurgeon
pip install graphsurgeon-0.4.5-py2.py3-none-any.whl 

把tensorrt的库和头文件添加到系统路径下

cd /data/TensorRT-7.2.2.3
sudo cp -r ./lib/* /usr/lib
sudo cp -r ./include/* /usr/include

验证安装环境:
YOLOv5—RTX3080 conda环境配置cuda11.1、cudnn8.0.5、pytorch1.8.0、tensorrt7.2.2.3、opencv4.4.0、deepstream5.1.0_第4张图片

7.安装OPENCV 4.4.0

(1)选择4.4.0版本下载,地址:https://opencv.org/releases/

(2)安装依赖库

sudo apt-get install -y cmake
sudo apt-get install -y libopencv-dev

(3)编译源代码

unzip opencv-4.4.0
cd opencv-4.4.0
mkdir build
cd build
cmake ..
make -j 10

(4)替换已经安装的版本

sudo make install

(5)将opencv的库添加至系统路径

sudo vim /etc/ld.so.conf

添加:include /usr/local/lib

8.安装DeepStream5.1.0

1.安装Gstreamer:

sudo apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

验证Gstreamer:dpkg -l | grep gstreamer
查看 Gstreamer 版本:gst-inspect-1.0 --version
(1)若出现:deepstream-app: error while loading shared libraries: libgstrtspserver-1.0.so.0: cannot open shared object file: No such file or directory
执行:

sudo apt install libssl1.0.0 libgstreamer1.0-0 gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav libgstrtspserver-1.0-0 libjansson4

(2)若出现:**(gst-plugin-scanner:30058): GStreamer-WARNING : 17:46:56.221: Failed to load plugin ‘/usr/lib/x86_64-linux-gnu/gstreamer-1.0/deepstream/libnvdsgst_inferserver.so’: libtritonserver.so: cannot open shared object file: No such file or directory
执行:sudo apt-get install gstreamer1.0-plugins-base gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-plugins-bad-videoparsers gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly

2.安装librdkafka:

git clone https://github.com/edenhill/librdkafka.git
cd librdkafka/
./configure
make
sudo make install
sudo mkdir -p /opt/nvidia/deepstream/deepstream-5.1/lib
sudo cp /usr/local/lib/librdkafka* /opt/nvidia/deepstream/deepstream-5.1/lib

3.安装DeepStream SDK 5.1
下载链接:https://developer.nvidia.com/deepstream-sdk
选择相应的安装包,如下图:
YOLOv5—RTX3080 conda环境配置cuda11.1、cudnn8.0.5、pytorch1.8.0、tensorrt7.2.2.3、opencv4.4.0、deepstream5.1.0_第5张图片

tar -xpvf deepstream_sdk_v5.1.0_x86_64.tbz2 
cd /opt/nvidia/deepstream/deepstream-5.1
sudo ./install.sh
sudo ldconfig

若出现:

/sbin/ldconfig.real: /usr/lib/libnvinfer_plugin.so.7 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libnvonnxparser.so.7 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libnvinfer.so.7 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libnvparsers.so.7 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libmyelin.so.1 is not a symbolic link

执行:

ln -sf  /usr/local/lib/libnvonnxparser.so.7  /usr/lib/libnvonnxparser.so.7
ln -sf  /usr/local/lib/libnvinfer_plugin.so.7  /usr/lib/libnvinfer_plugin.so.7
ln -sf  /usr/local/lib/libnvinfer.so.7  /usr/lib/libnvinfer.so.7
ln -sf  /usr/local/lib/libnvparsers.so.7  /usr/lib/libnvparsers.so.7
ln -sf  /usr/local/lib/libmyelin.so.1  /usr/lib/libmyelin.so.1

查看安装版本:deepstream-app --version-all
YOLOv5—RTX3080 conda环境配置cuda11.1、cudnn8.0.5、pytorch1.8.0、tensorrt7.2.2.3、opencv4.4.0、deepstream5.1.0_第6张图片

你可能感兴趣的:(深度学习环境配置,python,ubuntu,anaconda,cuda)