Darknet is an open source framework to train neural networks. It was implemented in C and CUDA. Here you can find a tutorial to train YOLO model for your own dataset. An interactive demo about the installation and running DarkNet can be found on the Colaboratory Notebook here: https://drive.google.com/open?id=1wtIQMypZQiIsDaX9aF_cC6pd3aVw6vzA.
First you have to clone the darknet repository from GitHub. Use the following commands:
Optional: enable CUDA and cuDNN usage before installing DarkNet. If you do not have these two libraries installed follow the steps described here: Install nVidia CUDA and cuDNN.
Configure DarkNet by changing the following lines in the Makefile:
Run the $ make command to install the framework.
It takes very long time to train YOLO from scratch. For this reason we will use some pre-trained weights.
In this example we are going to retrain our model for two classes. We will use the dataset generator, what we described on the page Dataset generator. By using it we will generate some learning data with Winnie-the-pooh and Tiger. Let's create a configuration file for tiny-yolo with two classes. Modify the file cfg/yolov2-tiny-voc.cfg and set the classes=2 value in the line 124 and features=35 in line 118.
Clone the dataset generator from the repo, install it and generate some learning data.
After this step you will have a training dataset with 5000 items.
Configure darknet by copying the voc.data and voc.names files to the right place.
You're ready to start training your model. Run the following command from the DarkNets root folder:
You should get similar outputs like on the image below:
Train YOLO with DarkNet.
Stop training by pressing CTR+C when the value of the IOU is close enough to 1,0. We propose to run 10000 steps for this dataset. The retrained model can be tested with this command:
The output should looks similar like this:
Predictions with the retrained tiny-yolo.
Here you can see the input image and the predictions for it. For more accurate score use the yolov2 and yolov3 models, which are deeper neural networks. They should be trained for a longer period: 20000 - 40000 steps are required.
Input image for object detection with Winnie-the-Pooh and Tiger.
Predicted image by using YOLO. Tiger and Winnie-the-Pooh were detected.
The retrained weights can be downloaded from the following link: https://drive.google.com/file/d/1eq0iaq8xjuf7FLRyfE2-K_HHt8EFA354/view?usp=sharing.