/DarkNet-YoloV4-Object-Detection

My self guide on how to use DarkNet framework to create Object Detection or Image Classification on Windows 10 using Nvidia CUDA GPU and OpenCV

Learning Notes - DarkNet YoloV4 Object Detection Tutorial for Windows 10

hqdefault

Learning Notes - DarkNet YoloV4 Object Detection Tutorial for Windows 10


Source: YouTube Com (2021) - Darknet YOLOv4 Object Detection Tutorial for Windows 10 on Images, Videos, and Webcams (TheCodingBug channel)

Table of Contents:

  1. Introduction: (0:00)
  2. Prerequisite: (0:21)
  3. Download Darknet: (03:31)
  4. Copy cuDNN and OpenCV Files: (3:55)
  5. Build Darknet using Visual Studio: (4:50)
  6. Object Detection on Images: (8:53)
  7. Object Detection on Videos: (9:48)
  8. Object Detection on Webcams: (10:34)

01 Introduction

Purpose: This is a tutorial on Installing DarkNet Yolov4 prepared by, and adopted from, TheCodingBug channel from YouTube. This learning notes is for my own guide for future reference and is shared for you who encounter a problem on installing DarkNet Yolov4 for Windows 10 using Nvidia CUDA GPU and OpenCV.

Steps:

  1. Building DarkNet
  2. Object Detection on Images
  3. Object Detection on Videos
  4. Object Detection on Webcam

02 Prerequisite

  1. Anaconda — package manager for mutiple version of virtual environment for Python and associated packages
  2. Visual Studio – Integrated Development Environment (IDE) by Microsoft®
  3. CUDA — Computing Unified Device Architecture (NVIDIA® GPU computing device driver)
  4. CUDNN — CUDA® Deep Neural Network (NVIDIA®)
  5. OpenCV — Python/C++ library for Computer Vision machine learning

(1) Anaconda Installer

Download Anaconda Installer: anaconda.com/products/individual then install it with default options.

Screen Shot 2021-08-04 at 16 25 46

Anaconda3 2020 11 (64-bit) Setup

ANACONDA  Choose the folder in which to instal Anaconda3 2020 11 (64-bit)

Anaconda3 2020 11 (64-bit) Setup

Anaconda3 2020 11 (64-bit) Setup

2020 11 (64-bit) Setup

(2) Microsoft Visual Studio

Next, download Visual Studio Community 2019 16.7.2 – the Community Edition: https://visualstudio.microsoft.com/vs/community/

Screen Shot 2021-08-04 at 16 32 31

Then, run the installer:

Screen Shot 2021-08-04 at 16 37 30

Select Desktop development with C++ option for Studio Code C++ support

components Language packs

Installation details

You may need to reboot your computer after installing Visual Studio.

(3) Cuda Toolkit Update

Now download CUDA Toolkit 11.0 Update Downloads: developer.nvidia.com/cuda-11.0-update1-download-archive?target_os=Windows&target_arch=x86_64

Choose Windows operating system for Select Target Platform.

Resources

CUDA Toolkit Archive

Choose CUDA Toolkit 11.0 Update 1 Downloads:

CUDA Toolkit 11 0 Update 1 Downloads

Choose the following options:

  • Operating System: Windows
  • Architecture: x86_84
  • Version: 10
  • Installer Type: exe (local)

Pasted Graphic 11

Pasted Graphic 12

cuDNN Download

Click Download cuDNN v8.0.5 (November 9th, 2020), for CUDA 11.0 to expand the driver list:

Library for Windows and Linux, Ubuntulx86_64   PPC architecture)

Click cuDNN Library for Windows (x86) now the driver will be downloading.

Extract the driver file (.zip) you just downloaded:

Pasted Graphic 15

Then copy the extracted files and folder inside cudnn-11.0-windows-x64-v8.0.5.39 to:

(C:) › Program Files › NVIDIA GPU Computing Toolkit › CUDA › v11.0 >

Pasted Graphic 17

Here you will replace some files and folders with new ones:

  • bin
  • include
  • lib
  • NVIDIA_SLA_cuDNN_Support.txt

Pasted Graphic 16


03 Download Darknet

First, download Darknet from AlexeyAB/darknet repository on GitHub (.zip format)

Pasted Graphic 10

Then, create a folder name darknet in your root directory C:\

Pasted Graphic 11

Open this directory: C:/darknet/darknet-master/build/darknet/x64

Pasted Graphic 12

Open new window: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/cudnn64_7.dll

Pasted Graphic 13

Copy the cudnn64_7.dll file to here: darknet › darknet-master › build › darknet › x64

Pasted Graphic 14

From OpenCV_CUDA > build › install > x64 > vc16 > bin, copy opencv_world440.dll to darknet › darknet-master › build › darknet › x64

Pasted Graphic 15

Inside darknet › darknet-master › build › darknet, open darknet.vcxproj file using code editor

Pasted Graphic 16

Inside darknet.vcxproj file, find CUDA 10 (ctrl+F) and change it to your CUDA version. For example: CUDA 10.1

Pasted Graphic 17

Inside darknet › darknet-master › build › darknet, open yolo_cpp_dil.vcxproj file using code editor

Pasted Graphic 18

Inside yolo_cpp_dil.vcxproj file, find CUDA 10 (ctrl+F) and change it to your CUDA version. For example: CUDA 10.1

Pasted Graphic 19

Open yolo_cpp_dil.vcxproj file using Visual Studio

Visual Studio

Click OK

Pasted Graphic 22

Change the Debug to Release

Pasted Graphic 23

On the right side, right click on yolo_cpp.dll

Pasted Graphic 25

Click Build

Pasted Graphic 27

Once it is done without any error, close it.

Pasted Graphic 40

Open darknet.sln with Visual Studio

Visual Studio

Change Debug -> release and Win32 -> x64

Pasted Graphic 41

Right click on darknet.sln, then click properties

Pasted Graphic 31

Click C/C++, go to Additional Include Directories. Click the dropdown button and click <Edit...>

Pasted Graphic 32

The display after clicking Edit

Pasted Graphic 33

Go to OpenCV_CUDA › build > install > include and copy the path

Pasted Graphic 35

Copy and paste OpenCV_CUDA\build \instal/\include path to the darknet.sln Additional Include Directories

Pasted Graphic 36

Edit the Preprocessor Definitions

Pasted Graphic 37

(optional) if you do not have a high end GPU: remove CUDNN_HALF

Pasted Graphic 38

Go to CUDA C/C++ -> Device -> Edit Code Generation

Pasted Graphic 39

Remove compute_75,sm_75

Pasted Graphic 42

Go to Linker -> General > Edit Additional Library Directories

Pasted Graphic 43

Go to OpenCV_CUDA > build › install › x64 › vc16 › lib and copy the path

Pasted Graphic 44

Paste it to Linker -> General > Edit Additional Library Directories

Pasted Graphic 45

Right click on darknet and build

Pasted Graphic 46

After finished without error, close the Visual Studio. You will find your darknet.exe inside darknet › darknet-master › build › darknet › x64

Pasted Graphic 47

Download YoloV4.weights file

Pasted Graphic 49

Pasted Graphic 50

Copy the yolov4.weights to here: darknet > darknet-master > build › darknet > x64

Pasted Graphic 51

Also copy a video to test the model (for ex: japan.mp4)

Pasted Graphic 52


04 Copy cuDNN and OpenCV Files: (3:55)


05 Build Darknet using Visual Studio: (4:50)


06 Object Detection on Images: (8:53)

Open Anaconda prompt. Run: darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4. weights

Pasted Graphic 53

Input image file name

Pasted Graphic 54

This is the result

bicyclo 0 92

Predicting time needed

Pasted Graphic 56


07 Object Detection on Videos: (9:48)

Run this command: darknet. exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights japan.mp4

Pasted Graphic 58

This is the result:

Pasted Graphic 59

The Average FPS: 13.5

Pasted Graphic 60


08 Object Detection on Webcams: (10:34)

Run this command: darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights-c 0

Pasted Graphic 61


Thank you for reading the repository 🙏

Good luck! 💪


tag: #learning #notes #darknet #yolov4 #object #detection #tutorial #windows #2021 #thecodingbugchannel #youtube #$$$$$