Jetson Xavier NX configuration YOLOV5 environment

1. pip3 and dependent library installation

sudo apt-get update
sudo apt-get install python3-pip python3-dev -y
sudo apt-get install build-essential make cmake cmake-curses-gui -y
sudo apt-get install git g++ pkg-config curl -y
sudo apt-get install libatlas-base-dev gfortran libcanberra-gtk-module libcanberra-gtk3-module -y
sudo apt-get install libhdf5-serial-dev hdf5-tools -y
sudo apt-get install nano locate screen -y
sudo apt-get install libfreetype6-dev -y
sudo apt-get install protobuf-compiler libprotobuf-dev openssl -y
sudo apt-get install libssl-dev libcurl4-openssl-dev -y
sudo apt-get install cython3 -y

In order to view the related system information conveniently:

sudo -H pip3 install jetson-stats

After the installation is complete, restart the system, and you can enter jtop in the terminal to call

2. Cmake

wget http://www.cmake.org/files/v3.13/cmake-3.13.0.tar.gz
tar xpvf cmake-3.13.0.tar.gz cmake-3.13.0/
cd cmake-3.13.0/
./bootstrap --system-curl
make -j4
echo 'export PATH=~/cmake-3.13.0/bin/:$PATH' >> ~/.bashrc
source ~/.bashrc

Ps: if it appears

Missing: CURL_LIBRARY CURL_INCLUDE_DIR

sudo apt-get install curl
sudo apt-get install libssl-dev libcurl4-openssl-dev

Large-capacity devices cannot be mounted

sudo apt-get install exfat-utils

Once done, you can try:

cmake --version

You can see the installed cmake version information

3. CUDA10.2, CUDNN8.0 installation

2.1 CUDA installation

Move the Cuda10.2 file to /usr/local

sudo cp -r [location of destination file] [location of destination]

For example, the original path of my file is: Download/cuda-10.2, my command should be sudo cp -r Download/cuda-10.2 /usr/local
Then decompress the targets in cuda-10.2 in /usr/local,

sudo tar xzvf targets.tar

Create a soft link:

sudo ln -s /usr/local/cuda-10.2/targets/aarch64-linux/lib lib64

sudo ln -s /usr/local/cuda-10.2/targets/aarch64-linux/include include
sudo chmod -R +x /usr/local/cuda-10.2

sudo ln -s /usr/local/cuda-10.2 /usr/local/cuda

sudo ldconfig

Environment variable configuration:

sudo vim ~/.bashrc

Keyboard input a will enter Insert mode, and then copy the information below to the end of the file

export CUBA_HOME=/usr/local/cuda-10.2
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-10.2/bin:$PATH

Then esc exits the Insert mode, then keyboard input: wq to save and exit
Update it:

source ~/.bashrc

Install some more dependencies:

sudo apt-get update
sudo apt-get install cuda-toolkit-10-2

Then you can verify cuda:

nvcc -V

2.2 CUDNN installation

Copy the three deb files in the cudnn file to the development board

Then execute in sequence:

sudo dpkg -i libcudnn8_8.0.0.180-1 + cuda10.2_arm64.deb
sudo dpkg -i libcudnn8-dev_8.0.0.180-1+cuda10.2_arm64.deb
sudo dpkg -i libcudnn8-doc_8.0.0.180-1+cuda10.2_arm64.deb

Then modify the installation path:

sudo cp /usr/include/cudnn.h /usr/local/cuda/include/

sudo cp /usr/lib/aarch64-linux-gnu/libcudnn* /usr/local/cuda/lib64/

Then you can open jtop to see

4. opencv

4.1 Install opencv system dependencies and codec libraries

sudo apt-get install build-essential -y
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff5-dev libdc1394-22-dev -y
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev -y
sudo apt-get install libxvidcore-dev libx264-dev -y
sudo apt-get install libatlas-base-dev gfortran -y
sudo apt-get install ffmpeg -y

Appeared in dependency installation:

solve:

sudo ln -sf /usr/local/cuda/lib64/libcudnn_adv_infer.so.8.2.1 /usr/local/cuda/lib64/libcudnn_adv_infer.so.8
 
sudo ln -sf /usr/local/cuda/lib64/libcudnn_ops_train.so.8.2.1 /usr/local/cuda/lib64/libcudnn_ops_train.so.8
 
sudo ln -sf /usr/local/cuda/lib64/libcudnn.so.8.2.1 /usr/local/cuda/lib64/libcudnn.so.8
 
sudo ln -sf /usr/local/cuda/lib64/libcudnn_ops_infer.so.8.2.1 /usr/local/cuda/lib64/libcudnn_ops_infer.so.8
 
sudo ln -sf /usr/local/cuda/lib64/libcudnn_adv_train.so.8.2.1 /usr/local/cuda/lib64/libcudnn_adv_train.so.8
 
sudo ln -sf /usr/local/cuda/lib64/libcudnn_cnn_infer.so.8.2.1 /usr/local/cuda/lib64/libcudnn_cnn_infer.so.8
 
sudo ln -sf /usr/local/cuda/lib64/libcudnn_cnn_train.so.8.2.1 /usr/local/cuda/lib64/libcudnn_cnn_train.so.8

4.2opencv installation

4.2.1 Change source

sudo vim /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe

install dependencies

sudo apt-get update
sudo apt-get install libjasper1 libjasper-dev

4.2.2 Installation

Download the source code of opencv and opencv_contrib, the version should be the same

Create a new build file in openccv-4.1.1

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/******/*****/opencv_contrib-4.1.1/modules ..
sudo make -j4
sudo make install

Configuration Environment:

sudo gedit /etc/ld.so.conf.d/opencv.conf

In the text that opens enter:

/usr/local/lib

Then save, close

sudo ldconfig

5. Pytorch

Copy the following files to the development board

Dependency installation:

sudo apt-get install libopenmpi2
sudo apt-get install libopenblas-dev
sudo apt-get install libjpeg-dev zlib1g-dev
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pillow

Then terminal input:

sudo pip3 install torch-1.8.0-cp36-cp36m-linux_aarch64.whl

6. torchvision

Environment configuration:

gedit ~/.bashrc

Add at the end:

export OPENBLAS_CORETYPE=ARMV8
source ~/.bashrc

cd into the torchvision folder, then:

sudo python3 setup.py install
export BUILD_VERSION=0.9.0
python3 setup.py install --user

test:

python3
import torch
import torchvision

If import does not report an error, it means ok

7. yolov5 dependency installation

sudo pip3 install matplotlib==3.2.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
sudo pip3 install --upgrade Cython
sudo apt-get remove python-numpy
sudo pip3 install numpy==1.19.4
sudo pip3 install scipy==1.4.1.
sudo pip3 install tqdm==4.61.2
sudo pip3 install seaborn==0.11.1
sudo pip3 install scikit-build==0.11.1
sudo pip3 install tensorboard==2.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

Here, an error will be reported because the python version is lower than 3.7, you can try to reduce the version of protobuf:

sudo pip3 install protobuf==3.19.6
sudo pip3 install PyYAML==5.4.1
sudo pip3 install thop
sudo pip3 install pycocotools

If the network is not good, the download will often fail due to ReadTimeoutError, you can consider:

sudo pip3 --default-timeout=1688 install matplotlib==3.2.2 -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn

–default-timeout=1688 is to make the detection delay longer to prevent direct error reporting due to network problems