This is to share some tips and my personal experinece to solve errors when installing YOLOv5 on Jetson Nano.
For anyone who would like to begin with "How to install YOLOv5 on Jetson Nano", please search it in google.
There are tons of githubs and blogs which kindly give you the instructions on "how to install YOLOv5 on Jetson Nano" in google.
The requirement for Python version is >= 3.7.0, but YOLOv5 actaully works with the pre-installed Python 3.6.9.
- When you use pre-installed Python 3.6.9, you are recommended to use
pip3 install
command to install libraries.
You can see that YOLOv5 on Jetson Nano works with Python 3.6.9 in the images below!
I tried to utilize the pre-installed opencv-python, but it kept giving me some errors.
For the ease of operation without trivial errors, I recommend you to install OpenCV in your Jetson Nano.
We all know that it is super annoying to install OpenCV in Ubuntu.
Surprisingly, Q-engineering has kindly shared his technology to build OpenCV very easily.
Just click the link above, and follow his perfect instructions!
Things to be careful when installing OpenCV:
-
OpenCV version 4.5.2: You need more memory for the version 4.5.2. Hence, you need to edit two files.
/sbin/dphys-swapfile
→CONF_MAXSWAP=4096
(this is only for OpenCV 4.5.2)/etc/dphys-swapfile
→CONF_SWARSIZE=4096
(this is only for OpenCV 4.5.2)
-
OpenCV version other than 4.5.2: You only need to edit one file.
/etc/dphys-swapfile
→CONF_SWARSIZE=4096
(this is only for OpenCV version other than 4.5.2)
-
Once your build is successfully completed, you can see from
jtop
that OpenCV has been successfully compiled with CUDA.
In my case, I uninstalled opencv-python. However, when running the yolov5 (detect.py), it kept installing the opencv-python and this eventually caused errors.
Therefore, I commented out opencv-python line in the requirements.txt file.
- opencv-python>=version → # opencv-python>=version
Some of you guys may suffer from larger screen frame than the size of the monitor.
I suffered as I am using a mini monitor for Jetson Nano (check the image below).
In this case, you can simply resolve this matter by checking the supported frame sizes of the camera, and add two more lines under the class LoadStreams:
in datasets.py file.
For your information, the location of datasets.py is yolov5 → utils → datasets.py
yolov5/
│ ...
└───utils/
│ datasets.py
│ ...
-
I uploaded the edited datasets.py in this repository! Please read the followings before you use it! 🙃
-
Check the supported frame sizes of the camera in the terminal.
v4l2-ctl --list-formats-ext
- You can see that the supported frame sizes are various such as 640(width)x480(height), 800(w)x600(h) etc.
-
Add two more lines under the
class LoadStreams:
in datasets.py file.- Make sure to add only the supported frame sizes!
int(cap.set(cv2.CAP_PROP_FRAME_WIDTH, supported width value))
int(cap.set(cv2.CAP_PROP_FRAME_HEIGHT, supported height value))
- If you add any unsupported values of width and height, you will receive GStreamer warning like the image below.
- Save the changes, and run YOLOv5 to check the frame size.
-
Open the .bashrc file in the terminal:
sudo vi ~/.bashrc
orsudo nano ~/.bashrc
-
Add
export OPENBLAS_CORETYPE=ARMV8
at the bottom of the .bashrc file, and save/exit. -
Type
source ~/.bashrc
in the terminal to apply the setting without rebooting the system.
Try to downgrade your torch and torchvision versions.
Please check the compatible torch and torchvision versions in the Nvidia developer forum.
Go to the link attached above, click Installation, then you can see the compatible versions as below:
In my case, I installed torch 1.7.0 and torchvision 0.8.1, and did not get the error anymore.
This is because your PIL has been compiled without libfreetype.
Try the following commands in the terminal.
sudo apt-get install libfreetype6-dev
sudo pip3 uninstall pillow
sudo pip3 install Pillow==7.1.2
- I used
pip3
because I am using python3.
Please visit my co-researcher's github as well!
https://github.com/jinsoo9595