Friday, August 28, 2020

How to train Yolov3 model on custom dataset

In this blog we are implement How to train Yolov3 model on custom dataset.


In this i have used kangaroo images for demo purpose you can use your images. but before this you Need To prepare dataset for model training.

Don't worry i have already covered in my previous blog. you can follow these blogs , also you can Watch video click here.

In this blog i have used google colab.you can use your system if you have good hardware resources.

Now come to the point you need to clone my project.

cmd :- git clone https://github.com/Manishsinghrajput98/yolo_traning.git

cmd :- cd yolo_traning

After finished this step now you have to copy/paste your data_darknet folder in our clone project Folder.(which is already covered in my previous blog. you need to follow this blogs for dataset preparation)

If you using google colab so you need to upload this complete folder in google drive.

For Google Colab

First you need to open google colab then login/sign-up then mount the drive for copy our project folder In colab and also enable gpu option.

After this step we need to install darknet. 

cmd :- git clone https://github.com/pjreddie/darknet.git

cmd :- cd darknet

cmd :- !make (! operator only for google colab if you use local so you don't need to add this operator)

cmd :- !mkdir yolo_training

Official website URL

Note :- You need to follow these steps for both (if you using local machine or google colab). | >

Note :- You need to read this and follow accordingly click here  

After this you need to run this script for copy your drive project in colab. (this step is not for local machine)

Source code

from distutils.dir_util import copy_tree

copy_tree("/content/drive/My Drive/yolo_traning", "/content/yolo_training/")

After this steps you need to split your dataset in train and test files.(train.txt, test.txt)

cmd :- cd yolo_training

cmd :- !python process.py data_darknet

After this step we are ready to train our model on custom dataset. Before this you need to download pre trained yolo model. I have already mentioned the path of this model in pretrained_model.txt txt file. just download these model files.

My Colab Notebook (you can use this)

open the pretrained_model.txt file and copy the path of pretrained model

cmd :- !wget https://pjreddie.com/media/files/darknet53.conv.74

After finish this steps we are ready to train our model on custom dataset. just run one more command For training.

If you using local machine for training. you need to replace the paths accordingly.

cmd :- !./darknet/darknet detector train /content/darknet/yolo_training/task.data /content/darknet/yolo_training/task.cfg /content/darknet/yolo_training/darknet53.conv.74 -gpus 0

like 

It takes time to train our model. 

Now come to the test our model on random images

cmd :- ./darknet detector test /content/darknet/yolo_training/task.cfg /content/darknet/yolo_training/backup/yolo_training_30000.weights /content/darknet/yolo_training/test_images/1.jpg -thresh 0.1

You need to change the path accordingly and also insert the path of images (local machine or Google colab)

If you want to python script for this you need to visit my previous blog these blog i have provide flask api do you can easily integrate in your project click here 

If you have any doubt so please comment

Thanks

1 comment:

  1. Really an awesome blog and informative content. I enjoyed your article. Keep sharing more stuff like this. Thank you.
    Data Science Training Institutes in Hyderabad

    ReplyDelete

If you have any doubts. Please let me know