Use yolov3 to train your own data set (c ++ vs2017 win10)

Reference: https://blog.csdn.net/la_fe_/article/details/81564420

https://blog.csdn.net/qq_31442743/article/details/81087346

If you continue to train the data set on the basis of the existing, refer to: https://mp.csdn.net/postedit/102964648

1. Prepare the data set , training picture, verification picture and their corresponding path name txt file

Unlike faster-rcnn, yolo also needs several txt files to run this script voc_label2.py to generate (see the top reference blog)

Replace \ in the paths in these three folders with /

D: \ software_engineer \ darknet \ darknet \ scripts \ VOCdevkit \ VOC2007 \ labels will also be generatedThis folder

voc_label2.py:

 

2. Prepare configuration files, need 3 configuration files

1.voc.data (the number of categories, the path of the two txt in step 1, the path of the class name, and the location of the training file)

2.voc.name

3.yolov3.cfg

The previous batch and subdivisions commented out under test during training, and commented out under training during test

Some parameters need to be changed here:

 [convolutional] 

size=1 

stride=1 

pad=1 

filters = 30 // Modify the number of kernel parameters of the last convolutional layer. There are three convolutional layers above each yolo layer

               // The calculation formula is still the number of categories of your own data filter = num × (classes + coords + 1) = 5 × (1 + 4 + 1) = 30 

// In the YOLOv3 version, filter = 3 × (classes + coords + 1) = 3 × (1 + 4 + 1) = 18, that is, 3 * (number of categories + 5)

activation=linear 

[region] 

anchors = 1.08,1.19,  3.42,4.41,  6.63,11.38,  9.42,5.11,  16.62,10.52 

bias_match=1 

classes = 1 // Number of classes , in this case 1 class 

coords = 4 

num = 5 

softmax=1 

jitter=.2 

rescore=1 

object_scale=5 

noobject_scale=1 

class_scale=1 

coord_scale=1 

absolute=1 

thresh = .6 

random=1

2. Training

Execute in D: \ software_engineer \ darknet \ darknet \ build \ darknet \ x64

./darknet detector train D:/software_engineer/darknet/darknet/cfg/voc.data D:/software_engineer/darknet/darknet/cfg/yolov3.cfg

If there is a pre-trained model, put it in the same folder as darknet.exe, and then add the name of the pre-trained model at the end of the instruction, for example: darknet53.conv.74,

If you want to train on an existing basis, you can't directly add the trained file name at the end. You need to run the following sentence to make a fine adjustment and change yolov3_last.weights to yolov3_last.conv.23. show)

./darknet partial cfg/darknet19_448.cfg yolov3_last.weights yolov3_last.conv.23 23

Then run the training./darknet detector train D: /software_engineer/darknet/darknet/cfg/voc.data D: /software_engineer/darknet/darknet/cfg/yolov3.cfg yolov3_last.conv.23

3 Test (change the yolov3.cfg file before testing)

(1) Single picture test

./darknet detector test D: /software_engineer/darknet/darknet/cfg/voc.data D: /software_engineer/darknet/darknet/cfg/yolov3.cfg D: /software_engineer/darknet/darknet/backup/yolov3_last.weights -i 0 -thresh 0.5 D: / work_place / door lock project / counting project deep learning target recognition / VOCdevkit / VOC2007 / JPEGImages / 00089.jpg

yolov3_last.weights is a trained file. In the backup, if you do n’t want to lose its path, you can copy it to the same folder as darknet.exe

(2) Change the test parameter to valid, and then remove the picture name (that is, the path is the path of the picture set folder). You can batch test the data in the test set and save it in the results folder. It is in txt format and is not intuitive. This batch test only runs the test set.

(3) Change the test video parameters to demo

./darknet detector demo data/coco.data cfg/yolov3.cfg yolov3.weights video_003.avi

Problems encountered:

1. Error when testing yolov3: cuda error: out of memory darknet: ./src/cuda.c:36: check_error: Assertion `0 'failed.

I suddenly reported this error when I trained to 800 times, but fortunately, it has already begun to converge at this time, and the training results can be used

2. After the batchsize is adjusted to 64, the training speed is super slow, and the size of the data set does not seem to have a big relationship. Training tens of thousands of voc2007 data sets is about the same speed as its own 200 data sets.

Published 59 original articles · Likes46 · Visits 30,000+

Guess you like

Origin blog.csdn.net/sinat_41852207/article/details/103026284