Yolo v3 Setup and training on Custom Data

Harshit Patidar Oct 09 2020 · 2 min read
Share this

Creating Steup-

Create a folder with name yolo 

We will download data from official website and paste above line by opening yolo folder in terminal

git clone https://github.com/pjreddie/darknet
After cloning folder will have darknet folder inside yolo 
open folder by giving command --  cd darknet 
after that type command make 
It will start built by make command i have already build thats why showing done

Download the Weight files - 

You already have the config file for YOLO in the cfg/ subdirectory. You will have to download the pre-trained weight file here (237 MB). Or just run this:

wget https://pjreddie.com/media/files/yolov3.weights
wget https://pjreddie.com/media/files/yolov3-tiny.weights
You will see both file in darknet folder 

Then run the detector by typing command-

./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
After that look in darknet folder image will generate and will look like-

Download Data we have Provide from Dashboard-

extract it in yolo folder
We have given dataset we will use this dataset for training 

1) Copy the dataset folder and paste in darknet folder.

2) Also create a new folder with name traning.

3) Also copy generate.py file and paste in darknet folder

we have done above steps 

Open generate.py file and give path of dataset according to your folder structure 

Now run generate.py by giving following command-

It will create two files in darknet folder which will look like-

Copy file in training folder that we have created in darknet

Changes in Yolo3-tiny.cfg File-

Now Open Yolo3-tiny.cfg file and do following changes

Uncomment 5,6 and 7 line

  • Change the number of filters for convolutional layer "[convolution]" just before every yolo output "[yolo]" such that the number of filters= 3 x (5 + #ofclasses)= 3x(5+1)= 18. The number 5 is the count of parameters center_x, center_y, width, height, and objectness Score. So, change the lines 127 and 171 to "filters=18".
  • line 127 give value 18
    line 171 give value 18

    For every yolo layer [yolo] change the number of classes to 1 as in lines 135 and 177.

    Open trainer.data and edit custom with training 

    Now in darknet/training folder it must have 5 file-

    a) test.txt and train.txt which we have already pasted

    b)Yolo3-tiny.cfg paste this file 

    c)object.names file that we have given in YoloFiles

    d) tainer.data we have given in YoloFiles

    ALL DONE ! Will DO Training Now

    Run the command on terminal-

    ./darknet detector train custom/trainer.data custom/yolov3-tiny.cfg darknet53.conv.74 

    Now your training is started

    After Training use yolo_opencv.py file for detection 

    use file that we have provided in YoloFiles 

    Read next