How to Run YoloV5 Real-Time Object Detection on Pytorch with Docker on NVIDIA Jetson Modules
Jetson AGX Xavier Jetson Nano Jetson Xavier NX 23 March 2021

In this post, we will explain how to run Yolo real-time object detection with Docker on NVIDIA Jetson Xavier NX. The process is the same with NVIDIA Jetson Nano and AGX Xavier. Firstly, we have to pull a Docker image which is based on NVIDIA L4T PyTorch. The image pull command can be seen below.




We can run the Docker container by using the below command.


docker run -it --gpus all -e DISPLAY=:0 -v /tmp/.X11-unix:/tmp/.X11-unix

When we go into the container, we create a new directory. Then we change our working directory with this new directory below. After, we pull the "yolov5" repository from github.

mkdir yolov5pytorch
cd yolov5pytorch/
git clone


We need to update "apt" package to avoid possible problems.



We install "nano" text editor. You can install a different text editor you would like to use.


apt-get install nano

We need to install some python packages. The required packages are identified in the "requirements.txt" file. Before the install of those packages, we need to make some arrangements inside the file.


"opencv-python", "torch" and "torchvision" should be changed as comment lines because there is the possibility of version incompatibility for those packages. We will install them manually later.



After making arrangements, we install the required packages by using the below command.


pip3 install -r requirements.txt

We need to install missing packages manually.


apt install -y python3-opencv

pip3 install torch

pip3 install torchvision

We have used "scp" command for getting image examples for yolov5. For using this command, you should install "openssh-server" package.

apt install openssh-server

On our host machine, we need to give the access permission to everyone for avoiding display problems.

xhost +

Now, we are ready to test yolov5 on our test image.


python3 --source ./data/images/example.jpg --conf 0.5


Here is the our test image.



For displaying image files inside the Docker container, we need to use gnome image viewer like "eog". We install it by typing below command.

apt-get install eog

After running this command, we can see the result image path from terminal.



For displaying the result image, please use below commands.

cd runs/detect/exp24
eog example.jpg

We can use another kind of sources like video or rtsp stream.



Thanks for reading!