Setting up Nvidia’s Jetson Nano : From Jetpack to YoloV5

Sahil Chachra
6 min readAug 21, 2021

--

In this blog, I will take you through several resources to step up your Jetson such as to install remote desktop, Pytorch, Tensorflow, etc. Also, I will talk about how to install other required libraries to run your deep learning tasks some tips.

Note : All the steps/procedures discussed/shared were used/tested by me on Nvidia Jetson Nano(B01, 4GB variant). The following packages were installed/set up on Jetpack 4.5 (R32.5.0). While writing this blog, Jetpack 4.6 has been released.

A brief on my Jetson’s setup

I am using Jetson Nano(B01) variant which has 4GB ram. I use 4A power adapter to power it. I have also installed a small fan on the heatsink to maintain the temperature(don’t know yet how effective it is). In terms of storage, I am using 64GB SD card from SanDisk. To work on jetson, I actually plug in a monitor, mouse and keyboard and use it like a separate machine for now. I tried using it via SSH, but then while learning you cannot entirely work through terminal/cmd. To access internet, I am using a ethernet cable which connects the jetson directly to my router. To capture live feed, I am using Logitech C270(HD) webcam.

To access internet, why am I not using Intel’s wifi/bluetooth adapter or USB wifi receiver? I am not using Intel’s adapter because right now I don’t see a need to use jetson wirelessly. I am using it with my monitor and other components plugged in. And the reason to not use USB wifi receiver is because each jetpack is based on some linux kernel version and those receivers work with few specific linux kernel’s versions only. So considering it as not so future proof, I did not consider using it.

Initial setup

  1. Head over to Nvidia’s official site to download Jetpack and follow the instructions to install it. You will need to download SD card formatter tool and jetpack image flashing tool. Everything will be mentioned in the steps. (Link for Jetpack 4.5 and steps — https://developer.nvidia.com/jetpack-sdk-45-archive)
  2. After flashing jetpack to SD card, plug it in and also attach monitor, keyboard and mouse.
  3. After booting it, increase the swap size to 4GB. ( If you don’t see the steps in the site then refer this video — https://www.youtube.com/watch?v=uvU8AXY1170)
  4. Now connect your jetson to internet via ethernet cable or Intel’s wifi/bluetooth module for jetson.
  5. Now run —
sudo apt-get update
sudo apt-get upgrade

6. After this install nano text editor —

sudo apt install nano

7. If you want to access jetson remotely with UI, setup VNC server. Link — https://medium.com/@bharathsudharsan023/jetson-nano-remote-vnc-access-d1e71c82492b . If you are on Windows, then follow the steps till installing and setting up VNC server. Then to access jetson via VNC, install VNC viewer. Open VNC viewer, go to File -> New connection -> in VNC server enter your jetson’s IP address and in name field give any name you want.

8. If you want to access jetson remotely without UI, go to cmd/terminal and type -> ssh your_jetson_username@jetson_IP_address. It will prompt for password. (You can also connect jetson to your system using mirco-usb if you don’t have access to internet. You connect by going to terminal and typing -> ssh your_jetson_username@192.168.0.55 . This should be the IP most probably)

Congratulations, your Jetson Nano is now ready!

Should I follow Jetson AI Fundamentals course now?

I spent few days with the course. The course helped me to setup my jetson and get some hands on. Do spend some time with this course and get familiar to jetson’s speed and UI. This course is very beginner friendly. They use NGC container to run a simple project which has required libraries pre-installed (but those libraries are accessible inside the container only). This course will teach you how to use jetson with headless mode(without monitor, mouse and keyboard).

Installing required libraries

Remember to use pip3 while installing these libraries(you have python 2 and python 3 both installed). Anaconda is not supported by Jetson as per today. If you want to create virtual environments you can use python’s venv or Archiconda.

  1. Install numpy version 1.19.4 only. Any version above this can cause problems while using Pytorch or Tensorflow (Faced issues myself — tensorflow threw core dumped error). To install numpy 1.19.4. Also install opencv :-
sudo apt-get install python3-pip
pip3 install cython
pip3 install numpy==1.19.4
pip3 install opencv-python

2. Download few dependencies before installing Pytorch:-

sudo apt-get install python3-pip libjpeg-dev libopenblas-dev libopenmpi-dev libomp-dev
sudo apt install libfreetype6-dev python3-dev zlib1g-dev

3. Head over to https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-9-0-now-available/72048 or search “download pytorch jetson” and open Nvidia’s website. Now, click on arrow and download Pytorch 1.8. It will download a .whl file. Install it using:-

pip3 install path_to_pytorch18.whl

4. Pytorch also requires torchvision library. To install it, (in the below command, vision and torchvision are separated by space — copy the entire clone command till the word torchvision and paste it in the terminal)

git clone — branch v0.9.1 https://github.com/pytorch/vision torchvision
cd torchvision/
sudo python3 setup.py install

5. Now come out of the torchvision folder by using command cd .. and verify installation of Pytorch and torchvision by importing them. If you see this error “Cannot find Python.h” while installing torchvision, kindly reinstall python3-dev package.

6. Now install Tensorflow 2.4.1 by following this article — https://qengineering.eu/install-tensorflow-2.4.0-on-jetson-nano.html . If gdown command(used to download tf2.4.1.whl file) doesn’t work, then simply copy the drive link from the steps and download the file yourself.

7. Verify the installation of tensorflow by importing it and printing the version.

Running Yolov5 on your Jetson

  1. Clone the repo and move inside the cloned folder
git clone https://github.com/ultralytics/yolov5.git
cd yolov5
export OPENBLAS_CORETYPE=ARMV8

2. Now type nano requirements.txt in terminal and comment out these packages as these are already installed -> numpy, tensorflow, torch, torchvision and opencv

3. Now install the remaining libraries using the following command. This process may take time as many of these libraries are downloaded and built locally on the jetson.

pip3 install -r requirements.txt

4. After installing, download Yolov5s model from the repository, place it in the yolov5 directory and run the following. If the following commands throws error, kindly look for missing dependencies.

python3 detect.py --weights yolov5s.pt --source 0 --device 0

Source 0 means you are using Webcam. (change the source to path of image or video if you don’t want to use live feed). Device 0 means that the model should be loaded in GPU.

5. Do checkout detect.py for more options while running inference on YoloV5s model (Yolov5s is a light weight model)

Few Tips

  1. Keep System monitor application on and always keep an eye on it. Jetson tends to lag when you have several tabs open on Chromium and parallelly you are running some inference.
  2. Restart the jetson if you see high ram usage even with no application open.
  3. If you are new to jetson, I highly recommend to use it with display, mouse and keyboard rather than via SSH.
  4. You may use VNC but at times it is very slow. You may use SSH if you know you won’t require UI for any task.
  5. Try to use jetson in a cool place. High temperature may damage it and also the SD card as it just sits below the heatsink.
  6. Try to use NGC containers as they provide many options, such as — providing entire DL libraries installed in a container. Just pull and run! (I couldn’t use it as the files/libraries I downloaded after pulling it were all gone when I restarted the jetson).
  7. Every time you run yolov5’s detect.py, the output is saved. Remember to delete the output if not needed else it will eat up space.

Conclusion

Hope these tips and steps might have helped you in setting up your jetson nano. The main goal of this blog was to guide you through the right steps to install these libraries instead of you keep on searching for these. Also, if you come across any community where people discuss/work on jetson, do let me know in the comments section of this blog. I would love to join to learn and contribute! Thanks for reading my blog. :-)

Connect with me on LinkedIn.

--

--

Sahil Chachra

AI Engineer @ SparkCognition| Applied Deep Learning & Computer Vision | Nvidia Jetson AI Specialist