yolov4 (darknet version) trains its own VOC format data set

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 darknetsource code, the previous article downloaded the old darknetsource code. However, the new ones darknetare yolov3still yolov4supported, so if you want to train yolov3, you can also use the latest ones darknet. However, the old ones darknetare 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 Makefilethe value of the item to be compiled to 1, as shown below:
Insert picture description here

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 VOCdevkitrun 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.dataFile : just modify it according to your actual path. Backup is used to store the weights after training.
Insert picture description here
2. data/voc.namesFile : Modify according to the actual type and category name of your own data set.
Insert picture description here
3. cfg/yolov4-custom.cfgDocuments :

  • Change line 6 batchtobatch=64

  • Change the 7th line subdivisionstosubdivisions=16

  • max_batchChange the 20th line to (the number of data set label types (classes)*2000but not less than 4000)

  • The line 22 stepsto max_batchthe 0.8fold and the 0.9fold

  • Set the two lines of 8.9 to width=416 height=416or other 32multiples

[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
  • filtersAnd classesparameters; there are three parts, the quickest way is to search directly yolo, and then change the filterssum above it classesto the actual value you need. These two values ​​satisfy the following formula:
filters = 3*(5+len(classes));
classes = len(classes)

Insert picture description here

Five, training

1. The downloaded yolov4.conv.137pre-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.cfgit, 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 ):
Insert picture description here
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-tinyto it. In this way, when you load the weights file will be loaded re-structure the right model is also set yolov4-tinyon it.

And you can see that yolov3the 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

Guess you like

Origin blog.csdn.net/qq_39507748/article/details/110850178