One, get the data set
1. If you can download the labeled data set, you can use it directly. Pay attention to check whether the organization format of the data set is the same as the VOC format.
2. If you don't have a ready-made data set, you may need to label it yourself. I will elaborate on this later if I have the opportunity. Need to use some labeling tools, such as labelImg, the specific use method can refer to the following two articles! ! !
Use labelImg to label images under windows
labelImg installation instructions
2. Download and compile darknet (under Ubuntu)
1. Download and compile
git clone https://github.com/AlexeyAB/darknet
cd darknet
make
note: Downloaded here is the latest darknet
source code, the previous article downloaded the old darknet
source code. However, the new ones darknet
are yolov3
still yolov4
supported, so if you want to train yolov3
, you can also use the latest ones darknet
. However, the old ones darknet
are not supported yolov4
, so please pay attention to this point! ! !
2. After the compilation is complete, you can use the following command to check
./darknet
If there is no problem, the following information will be output:
usage: ./darknet <function>
3. If you want to support GPU and OPENCV, you can modify it before compiling, and modify Makefile
the value of the item to be compiled to 1, as shown below:
3. Convert VOC data set format to YOLO data format
The previous article has explained in detail, Portal: VOC format data set to yolo (darknet) format
Another point is that you can VOCdevkit
run the following command in the same level directory after the format is converted :
cat 2007_train.txt 2007_val.txt > train.txt
The purpose is to merge the training data and the verification data into one file, and both are used for training. This is not necessary, but I think others do it like this, emmm! ! !
Four, parameter modification
The main areas that need to be modified are as follows:
1. cfg/voc.data
File : just modify it according to your actual path. Backup is used to store the weights after training.
2. data/voc.names
File : Modify according to the actual type and category name of your own data set.
3. cfg/yolov4-custom.cfg
Documents :
-
Change line 6
batch
tobatch=64
-
Change the 7th line
subdivisions
tosubdivisions=16
-
max_batch
Change the 20th line to (the number of data set label types(classes)*2000
but not less than 4000) -
The line 22
steps
tomax_batch
the0.8
fold and the0.9
fold -
Set the two lines of 8.9 to
width=416 height=416
or other32
multiples
[net]
# Testing
#batch=64
#subdivisions=16
# Training
batch=64 # 显存不够的图像可以改为16,32等
subdivisions=16 # 这里需要改
width=416 #可以改为32的倍数
height=416 #可以改为32的倍数
channels=3
momentum=0.949
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 4000 #改为classses*2000,但不小于4000
policy=steps
steps=3200,3600 #改为max_batch的0.8倍和0.9倍
scales=.1,.1
filters
Andclasses
parameters; there are three parts, the quickest way is to search directlyyolo
, and then change thefilters
sum above itclasses
to the actual value you need. These two values satisfy the following formula:
filters = 3*(5+len(classes));
classes = len(classes)
Five, training
1. The downloaded yolov4.conv.137
pre-trained model
Because you need to surf the Internet scientifically, here is the link to the network disk, emmm! ! !
链接:https://pan.baidu.com/s/1IWyTILlHUOgBGeDUIi4HhQ
提取码:w8x4
2. Start training:
./darknet detector train cfg/voc.data cfg/yolov4-custom.cfg yolov4.conv.137
Six, summary
If you don't want to use yolov4-custom.cfg
it, you just need to select the network structure you want to use, and then find its corresponding configuration file and pre-training weights . As shown in the figure below ( link provided: Portal ):
For example, in order to make the model smaller, you can choose yolov4-tiny.cfg
, as long as you remember that the weight file generated after the training is completed corresponds yolov4-tiny
to it. In this way, when you load the weights file will be loaded re-structure the right model is also set yolov4-tiny
on it.
And you can see that yolov3
the related configuration files and pre-training weights included here can also be trained yolov3
, and the related settings are similar.
note:Another point to note is that the data set processing method here is different from the official document. You can also refer to the steps in the official document:
https://github.com/AlexeyAB/darknet#how-to-train-tiny-yolo-to-detect-your-custom-objects