First, YOLO installation
YOLO Official Website: https://pjreddie.com/darknet/yolo/
1. Installing Darknet
git clone https://github.com/pjreddie/darknet
cd darknet
make
2. Download the weight file pre-trained weight
wget https://pjreddie.com/media/files/yolo.weights
3. Testing
./darknet detector Test Cfg/coco.data cfg/yolo.cfg yolo.weights data/dog.jpg
Or
./darknet detect cfg/yolo.cfg yolo.weights
Enter Image Path:
data/dog.jpg
second, YOLO training their own data set (VOC format)
Modified by URL: http://blog.csdn.net/ch_liu23/article/details/53558549 (i) building an VOC dataset
1. New Folder VOC2017 (first name + year)
Create a new three folder under the VOC2017 folder annotation, imagesets, and jpegimages, and place your own original image (. jpg) under the Jpegimages folder, and place the XML file under the annotation folder.
2, in the Imagesets folder, create a new three folder layout, main, segmentation, and then write the training image of the name of the text train.txt placed in the Main folder.
3. Run the script you wrote./write.sh
Generates a Train.txt file based on the tagged XML file that contains the file names of all the training set pictures
#!/bin/sh
#============ Get the file name ===========
echo-e "Please enter the folder path you want to read \ n The current path is ${pwd}"
read InputDir
echo "The folder path you entered is ${inputdir}"
echo-e "Please enter the file path where you want to save the data output \ nthe current path is ${pwd}"
read OutputFile
echo " Output saved file path is ${outputfile} "
: > $OutputFile #清空OutputFile #循环读取文件夹名 for file_a in
${inputdir}/*;
temp_file= ' basename $file _a '
echo $temp _file >> $OutputFile
Done
Note: The output file is the absolute path of the train.txt, which needs to be stripped out so that the suffix. XML is generated. (ii) training with Tiny-yolo 1. Generate related Files
After you have compiled the instructions for Darknet, create a new folder in the Darknet-master/scripts folder Vocdevkit, and then copy the entire VOC2017 folder to the Vocdevkit folder. Use the voc_label.py file in the Scripts folder to generate a series of training files and labels, with the following details:
(1) First need to modify the code in the voc_label.py, here the main modification of the data set name, and the category information, my is VOC2017, and all the samples used for training, no Val or test, and only detect people, cars, etc., so only five categories of targets, so the following settings:
sets=[(' ~ ', ' train ')]
classes = ["Person", "car", "electric bicycle", "bicycle", "motorcycle"]
Note: Delete the last two lines of output statements.
(2) After the modified in the directory Run command: Python voc_label.py, then the folder scripts\vocdevkit\voc2007 under the creation of a folder lables. At the same time, the Train_2017.txt file should also be generated under Scripts\, which contains the absolute path of all training samples (. jpg). 2. Configuration file Modification
(1) Take tiny-yolo-voc.cfg as an example, the network is a simple version of YOLO-VOC, relative speed will be faster, the main modification parameters are as follows:
FILTERS=50 //Modify the last layer of the convolution core parameter number, the formula is still the number of categories of their own data filter=numx (classes + coords + 1) =5x (5+4+1) =50 activation=
Linear
[region]
classes=5
Note: Other parameters such as learning_rate, max_batches, etc. can also be modified as required.
(2) Voc.names under the data file
Open the Voc.names file to see that there are 20 classes of names, in this case only five classes, can be changed to:
Person
car
electric bicycle
bicycle
Motorcycle
(3) Modify the Voc.data file in the CFG folder
classes= 5 //class number
train =/home/anngic/darknet/scripts/train_2017.txt //Training Sample Absolute path file
valid =/home/pjreddie/data/voc/2007_test.txt //absolute path file for test set
names = Data/voc.names // The Voc.names file that was modified in the previous step
backup =/home/anngic/darknet/results/ //Weight saved location generated after training
Attached: About the difficult case error correction method, you need to change all difficult to difficult.
Sed-i "S#difficult#difficult#g" ' grep ' difficult '-rl./'
(iii) training, testing
1. The above can be ordered training, you can find some pre-trained models on the official website as the initial value of the parameters, you can also directly train, training commands for
$./darknet detector train./cfg/voc.data cfg/tiny-yolo-voc.cfg
2. The training weight model is saved according to the number of iterations, as measured using the weight tiny-yolo-voc_6000.weights:
$./darknet detector test Cfg/voc.data cfg/tiny-yolo-voc.cfg results/tiny-yolo-voc_6000. Weights Data/images.jpg