Today we will try to build our environment to host PyTorch YOLOv5 You Only Look Once The most famous real-time object detection algorithm library with the Nvidia CUDA Driver support
We will need to do the following list
- Update Our Ubuntu 20.04
- Install Python And PIP
- Nvidia CUDA Driver with CUDA Toolkit version 11.3 for GPU Computing
- Nvidia cuDNN The Deep Nural Network Library version libcudnn8_8.2.0.53-1+cuda11.3
- Install Pytorch version 1.11.0 stable
- Install YOLOv5
Step1: Update Ubuntu 20.04
# apt update # apt upgrade
Step2: Install Python PIP AND Requirements
# apt install python3 python-is-python3 python3-dev pip virtualenv # apt install python3-pil # apt install ffmpeg libsm6 libxext6
Step3: Install And Check Prerequests
Pre-Requests Packages
Now we need to make sure that all Linux required headers are installed.
# apt install linux-headers-$(uname -r) -y
Check If Build-Essential development libraries and tools are installed
# apt install build-essential
Detect GPU CUDA Support
Check your GPU Graphic Card for the CUDA Enabled feature, the compute capability listed here for Nvidia CUDA GPUs Graphic Cards.
# lspci | grep -i nvidia
If (you found your GPU Card is CUDA Supported) { continue applying the following steps } else { Skip CUDA and cuDNN Installation Steps }.
Install Nvidia CUDA Driver Official Repository
According to the requirements version we will use the Nvidia CUDA Driver repository for Ubuntu 18.04 LTS, It's OK and compatible with Ubuntu 20.04 LTS
# wget -O /etc/apt/preferences.d/cuda-repository-pin-600 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin # apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub # add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /" # apt-get update
Check PyTorch Requirements
When looking for the stable version of PyTorch GPU CUDA Support requirements, it's the CUDA 11.33, while YOLOv5 we need to install Python>=3.8 environments with PyTorch>=1.7, plus a list of the following requirement packages
Step4: Install CUDA 11.3 And cuDNN 8.2
You can detect and select the correct version from the Nvidia official repository URL of the packages list.
# apt install --no-install-recommends cuda=11.3.0-1 # apt install --no-install-recommends libcudnn8=8.2.0.53-1+cuda11.3 libcudnn8-dev=8.2.0.53-1+cuda11.3 # echo 'export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}' >> ~/.bashrc
Step5: Install PyTorch
Install PyTorch With GPU CUDA Support
# pip install --no-cache-dir torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
Install PyTorch CPU Only
# pip install --no-cache-dir torch torchvision torchaudio
Check Your Installation
# python Python 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> torch.__version__ '1.11.0+cu102' >>>
Step6: Install YOLOv5
# git clone https://github.com/ultralytics/yolov5 # cd yolov5 # pip install --no-cache-dir -r requirements.txt
And you can start with YOLOv5 your hello world example at https://pytorch.org/hub/ultralytics_yolov5/ and https://github.com/ultralytics/yolov5