Skip to content

Tutorials

YOLO V3 – Install and run Yolo on Nvidia Jetson Nano (with GPU)

We’re going to learn in this tutorial how to install and run Yolo on the Nvidia Jetson Nano using its 128 cuda cores gpu.

All the steps described in this blog posts are available on the Video Tutorial, so you can easily watch the video where I show and explain everythin step by step.

Yolo is a really popular DNN (Deep Neural Network) object detection algorythm, which is really fast and works also on not so powerfull devices.

I explained in this post, how to run Yolo on the CPU (so the computer processor) using opencv, and I’m going to explain today how to run Yolo on the GPU (the graphic processor), to get more speed.

How to install YOLO V3?

Before showing the steps to the installation, I want to clarify what is Yolo and what is a Deep Neural Network.

YOLO is an Object Detection algorythm, and it’s the acronym of (You Only Look Once). An object detection algorythm need a DNN (Deep Neural Network) framework to run.

DARKNET is the DNN that was developed to run Yolo. And we’re going to see today how to install Darknet.

Let’s start with the installation.

  1. Update the libraries
    sudo apt-get update
  2. Export Cuda path
    export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  3. Download Darknet and Yolo
    git clone https://github.com/AlexeyAB/darknet
    cd darknet
    wget https://pjreddie.com/media/files/yolov3.weights
    wget https://pjreddie.com/media/files/yolov3-tiny.weights
  4. Enable the GPU
    We need to Edit the Makefile to enable the GPU, Cuda and Opencv. Let’s edit the Makefile by typing.
    sudo vi Makefile
    Set the values:
    GPU=1
    CUDNN=1
    OPENCV=1
    and the rest leave it as it is.
  5. Compile the Darknet
    make

The installation is now completed.

How to run YOLO V3?

You can run Yolo from the Linux terminal.
Once you open the terminal you need first to access the Darknet folder. So just type:

cd darknet

Then you can choose one of the following line, depending of the detection you want to perform.

Image detection:
Edit “dog.jpg” with the path of your image.

./darknet detector test cfg/coco.data yolov3.cfg yolov3.weights -ext_output dog.jpg

Detection from Webcam:
The 0 at the end of the line is the index of the Webcam. So if you have more webcams, you can change the index (with 1, 2, and so on) to use a different webcam.

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -c 0

Detection from a Videofile:
Edit “test.mp4” with the path of your videofile.

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -ext_output test.mp4

For more and detailed info, you can check the darknet github page or evaluate the purchase of my Object Detection course .

40 comments

  1. Thank you for the tutorial. I have used your instructions to run darknet on jetson nano, tx2 and Xavier. I think the tags OPENMP and LIBSO should both be set to 1 for nano. LIBSO will produce a .so file which can be imported into python to run inference. OPENMPI is supported on jetson nano as well. What do you think?

  2. Thank you so much for this tutorial. It really gave me a structure to follow and understand what to do.
    On the last step I always got an error with the last command. It always gave me the error: VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupportet by OpenCV and the video stopped. So if anyone has the same error: It helped to change the first 4 lines in the yolo.cfg file (which is in darknet/cfg) to:
    batch=1
    subdivisions=1
    width=220
    height=220
    And then run in darknet:
    ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights ‘nvarguscamerasrc auto-exposure=1 ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink -e’

    1. when I try to run by simple camera -0 option, a green window is popping up. I tried your solution but this error is coming:

      bash: syntax error near unexpected token `(‘

      1. I think there is a typo in my suggested command: Try to use this ‘ instead of ’
        That means: ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights ‘nvarguscamerasrc auto-exposure=1 ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink -e’

  3. while compiling the darknet , i am getting the following error:
    ./src/image_opencv.cpp:15:10: fatal error: opencv2/core/version.hpp: No such file or directory
    #include
    ^~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    Makefile:149: recipe for target ‘obj/image_opencv.o’ failed
    make: *** [obj/image_opencv.o] Error 1
    kindly provide the solution

  4. Why huge difference in deepstream when run using following link https://devtalk.nvidia.com/default/topic/1050377/jetson-nano/deep-learning-inference-benchmarking-instructions/ for tiny-yolov3 it gives output as:
    Total number of images used for inference : 500
    100 %
    Network Type : yolov3-tiny Precision : kHALF Batch Size : 1 Inference time per image : 29.6826 ms which is equivalent to approximately 33fps .
    While using darknet tiny-yolov3 gives 16fps and as per given benchmark, it is 25fps. Why so?

  5. There is a typo in your `Image detection:` section, requires (noting ‘cfg/yolov3.cfg’):

    ` ./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights -ext_output dog.jpg`

  6. Can some one please help understand how are you able to change the value of below ? I tried multiple times but the keyboard / mouse dosent accept to remove the 0, is there any other key I need to click to change ?
    Set the values:
    GPU=1
    CUDNN=1
    OPENCV=1

  7. shubh@shubh-desktop:~/darknet$ make
    chmod +x *.sh
    g++ -std=c++11 -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config –cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -I/usr/local/cudnn/include -c ./src/image_opencv.cpp -o obj/image_opencv.o
    Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found
    ./src/image_opencv.cpp:15:10: fatal error: opencv2/core/version.hpp: No such file or directory
    #include
    ^~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    Makefile:159: recipe for target ‘obj/image_opencv.o’ failed
    make: *** [obj/image_opencv.o] Error 1

    unable to run make

    1. Hi I manage to fix this:
      1. Try search opencv4.pc and notice the location of the file
      2. Then rename it to opencv.pc
      3. Add `export PKG_CONFIG_PATH=/path/to/` to .bashrc so terminal recognized it.

      Then you are good to go

      1. Hi Daniel,
        I’m unable to find the opencv4.pc but i found the opencv4 folder only
        can you please guide me how to export the path of bashrc to terminal for it’s recognition

  8. Is there anyone who ca help me out with this error
    after make my terminal popping up with this error
    chmod +x *.sh
    make: *** No rule to make target ‘obj/image_opencv.o’, needed by ‘darknet’. Stop.

  9. Hi guys. I recently installed yoloV3 as this instruction and encountered error during compiling
    I installed Jetpack 4.3. The error said that “nvcc not found”, so I googled and found a solotuion.
    Instead of typing the commands in “Export CUDA path”, typing the following commands worked fine for me.
    export PATH=”/usr/local/cuda/bin:$PATH”
    export LD_LIBRARY_PATH=”/usr/local/cuda/lib64:$LD_LIBRARY_PATH”

    1. DId you change the export path from step 2?
      I still keep getting
      /bin/sh: 1: nvcc: not found
      Makefile:170: recipe for target ‘obj/convolutional_kernels.o’ failed
      make: *** [obj/convolutional_kernels.o] Error 127
      did you change the line of code in Makefile also for NVCC?
      NVCC=nvcc
      or did you leave it alone.

      1. I searched for the nvcc compiler and found it in /usr/local/cuda10.0/bin
        adding that to the PATH solved the problem. export PATH=$PATH:/usr/local/cuda10.0/bin

  10. Thanks so much for your good work. I need your assistance on the conversion of rectangle bounding box of yolov3 to circle bounding in the image.c of darknet… I will glad if you provide me this edited image.c file and a script to convert my Yolo txt of images to circle bounding. Thanks

  11. I’m using darknet on a Jetson Nano and get about 3.3 fps with a custom model (using your panda tutorial – thanks). Using darknet, how can I get the bounding box coordinates of tracked objects with a webcam in a python script? I’m trying to capture this data and so I can send it to a microcontroller. Thank you.

Join the discussion