How to train YOLOv3 to detect custom objects

YOLO V3 Details — Feature Extractor:

We use a new network for performing feature extraction. Our new network is a hybrid approach between the network used in YOLOv2, Darknet-19, and that newfangled residual network stuff. Our network uses successive 3 × 3 and 1 × 1 convolutional layers but now has some shortcut connections as well and is significantly larger. It has 53 convolutional layers so we call it…. wait for it….. Darknet-53!. If you want to read about yolo v3 please click here.

Yolo v3 - Architecture

Dataset Preparation:

The dataset preparation similar to How to train YOLOv2 to detect custom objects blog in medium and here is the link.

Training:

Download Pretrained Convolutional Weights:

Preparing YOLOv3 configuration files

YOLOv3 needs certain specific files to know how and what to train. We’ll be creating these three files(.data, .names and .cfg) and also explain the yolov3.cfg and yolov3-tiny.cfg.

  • cfg/cat-dog-obj.data
  • cfg/cat-dog-obj.names
classes= 2 
train = cat-dog-train.txt
valid = cat-dog-test.txt
names = cat-dog-obj.names
backup = backup/
cat
dog

Step 1: (If you choose tiny-yolo.cfg)

i) Copy the tiny-yolo.cfg and save the file name as cat-dog-tiny-yolo.cfg

manivannan@manivannan-whirldatascience:~/YoloExample/darknet-v3$ cd cfg
manivannan@manivannan-whirldatascience:~/YoloExample/darknet-v3/cfg$ cp yolov3-tiny.cfg cat-dog-yolov3-tiny.cfg
  • Line 3: set batch=24, this means we will be using 24 images for every training step
  • Line 4: set subdivisions=8, the batch will be divided by 8 to decrease GPU VRAM requirements.
  • Line 127: set filters=(classes + 5)*3 in our case filters=21
  • Line 135: set classes=2, the number of categories we want to detect
  • Line 171: set filters=(classes + 5)*3 in our case filters=21
  • Line 177: set classes=2, the number of categories we want to detect
manivannan@manivannan-whirldatascience:~/YoloExample/darknet-v3$./darknet detector train cfg/cat-dog-obj.data cfg/cat-dog-yolov3-tiny.cfg darknet53.conv.74

Step 2: (If you choose yolov3.cfg)

i) Copy the yolov3.cfg and save the file name as cat-dog-yolov3.cfg

manivannan@manivannan-whirldatascience:~/YoloExample/darknet-v3$ cd cfg
manivannan@manivannan-whirldatascience:~/YoloExample/darknet-v3/cfg$ cp yolov3.cfg cat-dog-yolov3.cfg
  • Line 3: set batch=24, this means we will be using 24 images for every training step
  • Line 4: set subdivisions=8, the batch will be divided by 8 to decrease GPU VRAM requirements.
  • Line 603: set filters=(classes + 5)*3 in our case filters=21
  • Line 610: set classes=2, the number of categories we want to detect
  • Line 689: set filters=(classes + 5)*3 in our case filters=21
  • Line 696: set classes=2, the number of categories we want to detect
  • Line 776: set filters=(classes + 5)*3 in our case filters=21
  • Line 783: set classes=2, the number of categories we want to detect
manivannan@manivannan-whirldatascience:~/YoloExample/darknet-v3$./darknet detector train cfg/cat-dog-obj.data cfg/cat-dog-yolov3.cfg darknet53.conv.74

Important Notes while training:

Weights only save every 100 iterations until 900, then saves every 10,000. If you want change the process please follow the link.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Manivannan Murugavel

Manivannan Murugavel

Artificial Intelligence and Data Science