Yolov5 Object Detection on NVIDIA Jetson Nano | by Amirhossein Heydarian | Towards Data Science

This article represents JetsonYolo which is a simple and easy process for CSI camera installation, software, and hardware setup, and object detection using Yolov5 and openCV on NVIDIA Jetson Nano. This project uses CSI-Camera to create a pipeline and capture frames, and Yolov5 to detect objects, implementing a complete and executable code on Jetson Development Kits. Check out the CodePlay jetson nano youtube playlist for video instructions and JetsonYolo Github.
One of the most common cameras used with the Jetson Nano is the Raspberry Pi Camera Module V2, but what if you need a higher resolution? Recently I tried to use the Waveshare IMX477 CSI camera for a project but had trouble connecting it to the board. Finally, after trying several different methods, I came up with a simple process and decided to share it with others. This article consists of several parts including, hardware, driver, and python libraries installation, and finally, the Yolov5. These steps are all essential for object detection using the camera on the Jetson Nano board.
Install the camera in the MIPI-CSI Camera Connector on the carrier board. Pull up the plastic edges of the camera port. Push in the camera ribbon and make sure that the pins on the camera ribbon face the Jetson Nano module. Push the plastic connector down. You can use the Arducam camera setup guide for more info.
By default, NVIDIA JetPack supports several cameras with different sensors, one of the most famous of which is the Raspberry Pi camera v2. But if you are using another camera type, you need to install a sensor driver. A 12.3 MP camera with an IMX477–160 sensor is used in this project, requiring an additional driver to connect. Arducam provides an IMX477 driver with easy insulation for cameras with an IMX477 sensor. (Make sure to check the website and use the latest commands.)
Download automatic installation script:
cd ~wget https://github.com/ArduCAM/MIPI_Camera/releases/download/v0.0.3/install_full.sh
Install the driver:
chmod +x install_full.sh./install_full.sh -m imx477
And finally, enter y to reboot the board.
Use the following command to check if the camera is recognized correctly.
ls /dev/video0
You can use the JetsonHacks python code to capture frames from the camera using OpenCV.
Yolov5 model is implemented in the Pytorch framework. PyTorch is an open-source machine learning library based on the Torch library, used for computer vision and natural language processing applications. Here is a complete guide for installing PyTorch & torchvision on Jetson Development Kits.
Clone JetsonYolo repository on Jetson nano.
git clone https://github.com/amirhosseinh77/JetsonYolo.git
Select the desired model based on model size, required speed, and accuracy. You can find available models here in the Assets section. Download the model using the command below and move it to the weights folder.
cd weightswget https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
Run JetsonYolo.py to detect objects with the camera.
python3 JetsonYolo.py
This article focuses on using an IMX477 camera to capture frames and perform object detection. Setting up this type of camera requires an additional driver installation step, and Arducam has provided a driver for Jetson Linux Driver (L4T). After installing the necessary drivers and Python libraries, the Yolov5 is implemented on the Jetson Nano as JetsonYolo and achieves satisfactory results with 12 frames per second.