How to Run YOLOv4 on Images and Video

Darknet and YOLOV4 Installation Documentation

Hey guys and welcome back, so in the last lecture, we spent some time setting up the prerequisites for YOLOv4, like Visual Studio, Python, CUDA, CuDnn and OpenCV. If you have not completed the previous tutorial, then I highly suggest that you do because this lecture builds upon the steps we took in the previous tutorial. So if you have completed that tutorial, then this lecture we are going to be installing Darknet Framework and thus YOLOv4. By the end of this tutorial you will be able to implement YOLOv4 on an Image and on Video.

I’m sure you must be excited, Okay so let’s get into the tutorial. Watch the Full Video Tutorial Here

Step 1

  • Cloned repository from official Github of AlexyAB [link]

Step 2

  • Copy OpenCV_ffmpeg and _world dll’s for 4.1.0 version(can be used for OpenCV video processing) near to darknet.exe

Step 3

  • Copied cuDNN.dll(for accelerating the neural network processes) near to darknet.exe

Step 4

  • Change the CUDA version if you’re not using CUDA 10.0.
  • I’m using 10.2 so made change in two files
darknet.vcxproj [Line:55]
yolo_cpp_dll.vcxproj [Line:309]
  • Save it.

Step 5

Compile yolo_cpp_dll.vcxproj with updated CUDA version

  • Open yolo_cpp_dll.vcxproj with VS.
  • Open VS and Select Release and x64.
  • Right click on yolo_cpp_dll and select build.
  • Should be -1 succeeded without fail-
  • If failed then make sure you have followed upper steps properly.

Step 6 - Compile darknet.sln

  • Open darknet.sln with VS
  • Set Release and x64
  • Right click on darknet and select properties
  • Make Four changes
C/C++ -> General -> Additional Include Directories: C:\OpenCV\build\install\include .
  • Click Ok and Apply If you followed my instructions then path should be same -
C/C++ -> Preprocessor -> Preprocessor Definitions
  • Remove CUDNN_HALF as Yolo v4/3 uses Tensor cores We don’t need to use it for 1080Ti [Optional] If you have GPU with Tensor Cores (nVidia Titan V / Tesla V100 / DGX-2 and later) then add CUDNN_HALF for speedup in detection 3x and training 2x.
CUDA C/C++ -> Device -> Code Generation
  • Remove compute_75, sm_75 if you’re not using CUDA 10.0 - Linker -> General Add lib from OpenCV build
C:\OpenCV\build\install\x64\vc16\lib
  • Right click on darknet and select build
  • After the successfully build try and import darknet in Python from x64 directory Should be imported otherwise right click on darknet and select clean the build and try to follow upper steps properly.

Step 7 Run Detection on Images

darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights It’ll ask for the input path of the image

Step 8 Run Detection on Videos

darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights PATH_TO_THE_VIDEO

If you got this working then GREAT!! Now what I want you to do, is to try this out with a different images and video and post a link to your video/images in the comments, I would love to see what images and videos that you guys have tried and testing. If not, try and go back and follow the steps precisely and do a clean build where applicable.

If you are interested in Enrolling in my upcoming course on YOLOv4 then sign up over here when it gets released - Click Here

YOLOV4 Course - Coming Soon!

Road Map

Okay great! So now that we have YOLOv4 working, lets take a look out road map going forth:

  • Tut 1 we spend setting up the pre-requisites
  • Tut 2, we will install Darknet & implement YOLOv4 on an image
  • Tut 3 we take YOLOv4 into real time object detection on video, for processing and saving a video and detection on a webcam.
  • Tut 4, we create a social Distancing App using YOLOv4.

Okay so let’s get into the tutorial - Click this link to get started

Comments

Popular posts from this blog

Movidius NCS (with Raspberry Pi) vs. Google Edge TPU (Coral) vs. Nvidia Jetson Nano – A Quick Comparison

OpenCV AI Kit - An Introduction to OAK-1 and OAK-D

OpenCV AI Kit - Interview with CEO Brandon Gilles