Yolo3 custom training notes
To train a model, YOLO training code expects:
* NAMES File
* CFG file
* train.txt file
* test.txt file
* DATA file
* Pretrained weights (optional)
Images and Labels
The images and labels should be located in the same directory. Each image and label is related to its counterpart by filename.
001.jpg, the corresponding label should be named
The file containing the labels is a plain text file. Each line contains a bounding box for each object. The colums are separated by spaces, in the following format:
classID x y width height
height should be expressed in a normalized pixel with values from 0 to 1.
y correspond to the coordinate of the center of the bounding box.
Yolo includes the following python helper function to easily achieve that:
def convert(size, box):
dw = 1./(size)
dh = 1./(size)
x = (box + box)/2.0 - 1
y = (box + box)/2.0 - 1
w = box - box
h = box - box
x = x*dw
w = w*dw
y = y*dh
h = h*dh
This file contains the label string for each class. The first line corresponds to the class 0. second line corresponds to the class 1, and so on.
i.e. Contents of
This would create the following relationship:
|Class ID (labels)
This file is a darknet configuration file. To simplify the explanation:
Modifications required to train, according to:
GPU memory available:
batch=64 #Number of images to move to GPU memory on each batch.
Number of classes
The number of classes should be set on each of the
[yolo] sections in the CFG file.
classes= NUM_CLASSES (1,2,3,4) should match names file.
Number of Filters
[yolo] section, the number of filters in the
[convolutional] layer should also be updated to match the following formula:
classes=(classes + 5) * 3
For instnace, for 3 classes:
This plain text file contains each of the images that will be used for training. Each line should include the absolute path to the Image.
In the same way as the
train.txt file, this text file contains the paths to the images used for testing, one per line.
This plain text file summarizes the dataset using the following format:
train = /home/user/dataset/train.txt
valid = /home/user/dataset/test.txt
names = /home/user/dataset/classes.names
backup = /home/user/dataset/backup
./darknet detector train file.data file.cfg darknet53.conv.74