Jetson nano+yolov5 target detection_Updated in October 2023

Lightning protection: I used it myself, but when I copied it, I found that all the pictures were gone

The note is here: https://waiting-carol-542.notion.site/Jetson-nano-yolov5-6b27ef50ae7f4f4082561af118e72594

Environment configuration

Step 1: Download the image file

First, download the Jetson Nano image file from the NVIDIA developer website. It is recommended to use an SD card of at least 32GB.

NVIDIA Developer Website Download Link

After the download is complete, unzip the image file.

Untitled

Untitled

Official website tutorial https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#intro

Step 2: Download the programming tool

Download Etcher, a tool for writing images to SD cards.

Etcher download link

Untitled

Step 3: Format SD card

Use the SD Card Formatter tool to format the SD card.

SD Card Formatter download link

Untitled

Step 4: Burn the image

Use the Etcher tool to write the downloaded image file to the SD card. This process may take approximately 20 minutes.

Untitled

Step 5: Start Jetson Nano

Insert the SD card into the Jetson Nano, connect the HDMI cable, and power on. The initial startup may be slow.

Untitled

Untitled

Memo: name hs, password 1

(The author feels that adding an extra keyboard and mouse is too troublesome. The next step is to study how to use vnc to log in remotely)

  1. Download vnc-viewer: Download VNC Viewer | VNC? Connect

(This website is like a pirated version)

Then refer to this blog: Use of Jetson Nano (1): Image burning, VNC remote connection configuration and system environment configuration_NVIDIA nano burning environment, networking, vnc-CSDN blog vnc &utm_medium=distribute.pc_search_result.none- task-blog-2~all~sobaiduweb~default-2-117968818.142^v93^koosearch_v1 & amp;spm=1018.2226.3001.4187

This can also be done: Playing with Jetson Nano (1) Boot preparation and remote connection settings_jetson configuration static ip-CSDN blog

The delay is too high, so use ssh.

SSH remote login

  1. Look at the device’s IP address (IPv4 address) on the external display and write it down. Then start OpenSSH in the terminal.
  2. You can now log in to the device remotely using VSCode or another SSH client. If passwordless login is required, copy the public key of the local computer to the authorized_keys file in the .ssh folder of the device. You can also try running service sshd restart to resolve any SSH connection issues.

Untitled

Untitled

Untitled

Resolving re-login issues

If you are unable to connect when you try to log in again after a month, it may be due to an SSH service configuration issue. Please review the following workarounds:

Untitled

Untitled

Jetson Nano environment configuration

Step 1: Download and Install DeepStream

  1. Download the .deb file for DeepStream 6.0 SDK from the link provided.
  2. Follow NVIDIA’s official DeepStream installation guide to install it.

DeepStream Installation Guide Link

Just follow the guide.

Untitled

Just do this (don’t run deepstream first)

Untitled

sudo apt update

sudo apt install -y python3-pip

pip3 install –upgrade pip

Step 2: Clone YOLOv5 repository

Use the following command to clone the YOLOv5 repository from Ultralytics on GitHub.

git clone <https://github.com/ultralytics/yolov5>

Then, go into the yolov5 directory and switch to the v7.0 branch:

cd yolov5
git checkout v7.0

Step 3: Install dependencies

In the yolov5 folder, update the requirements.txt file:

NOTE: torch and torchvision are not included for now as they will be installed later.

It takes a long time to compile opencv, remember to change it to

pip3 install opencv-python==4.3.0.38

Note: The opencv version also needs to be modified.

Untitled

NOTE: torch and torchvision are not included for now as they will be installed later. Install necessary packages:

sudo apt-install-y libfreetype6-dev

Install dependencies:

pip3 install -r requirements.txt

Install numpy 1.19.4:

pip3 install --force-reinstall --no-cache-dir numpy==1.19.4

Step 4: Install PyTorch

First install PyTorch v1.10.0. The following commands will help you do this:

cd ~
sudo apt-get install -y libopenblas-base libopenmpi-dev
wget <https://nvidia.box.com/shared/static/fjtbno0vpo676a25cgvuqc1wty0fkkg6.whl> -O torch-1.10.0-cp36-cp36m-linux_aarch64.whl
pip3 install torch-1.10.0-cp36-cp36m-linux_aarch64.whl

Step 5: Install TorchVision

Install TorchVision using the following command:

sudo apt install -y libjpeg-dev zlib1g-dev
git clone --branch v0.11.1 <https://github.com/pytorch/vision> torchvision
cd torchvision
sudo python3 setup.py install

The third line of construction starts:

Untitled

Untitled

YOLOV5 instance running

  1. DeepStream Configuration for YOLOv5

    cd ~
    
    git clone <https://github.com/marcoslucianops/DeepStream-Yolo>
    
    git checkout e7c77ee9fe78d8b82caa5b01574792af429fe923
    
    cp DeepStream-Yolo/utils/gen_wts_yoloV5.py yolov5
    
    cd yolov5
    
    wget <https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5s.pt>
    
    python3 gen_wts_yoloV5.py -w yolov5s.pt
    
  2. Copy the generated cfg and wts files into the DeepStream-Yolo folder

cp yolov5s.cfg ~/DeepStream-Yolo
cp yolov5s.wts ~/DeepStream-Yolo
  1. Open the DeepStream-Yolo folder and compile the library
cd ~/DeepStream-Yolo
CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo # for DeepStream 6.1
CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo # for DeepStream 6.0.1 / 6.0 (Used this one in my case)
  1. Edit the config_infer_primary_yoloV5.txt file according to your

    [property]

    custom-network-config=yolov5s.cfg

    model-file=yolov5s.wts

  2. Edit the deepstream_app_config file

[primary-gie]

config-file=config_infer_primary_yoloV5.txt (CHECK THIS USUALLY THE DEFAULT VALUE IS DIFFERENT)

  1. Change the video source in deepstream_app_config file. Here a default video file is loaded as you can see below

[source0]

uri=file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4

Run the Inference

deepstream-app -c deepstream_app_config.txt

You have to wait for a while, then you can finally run away