Skip to content

Latest commit

 

History

History
88 lines (71 loc) · 4.3 KB

README.md

File metadata and controls

88 lines (71 loc) · 4.3 KB

reference:https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

下载与测试darknet yolo:


git clone https://github.com/pjreddie/darknet
git clone https://github.com/AlexeyAB/darknet
cd darknet
修改Makefiles文件,CUDA,OPENCV,GPU,ARCH


make

测试下载的YOLO内容(下载权重后下载测试图片检测):


for v3:
wget https://pjreddie.com/media/files/yolov3.weights
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg -thresh 0.5


for tiny:
wget https://pjreddie.com/media/files/yolov3-tiny.weights
./darknet detect cfg/yolov3-tiny.cfg yolov3-tiny.weights data/dog.jpg -thresh 0.5

For webcam and video:


for the webcam:
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights
for the video:
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights

训练自己的数据集

制作数据集、统一数据格式


首先制作voc格式数据集,本质上就是1.jpg-1.txt, 内容:0 0.1 0.2 0.1 0.2 归一化的(x,y,w,h) 使用voc_label.py or divide.py
(先分割数据集,然后把分割后不带后缀的文件名写在train.txt内,将jpg文件路径写在train.txt/val.txt里,最后合并为train_final, 在之后我们把对应的数据集txt转化成VOC格式,并将对应的txt,放在labels/%.txt里,最后合并到all_labels.txt)

训练数据预处理


使用gen_anchor.py,生成k-means得到的anchor,
需要修改内容:width&height: 32倍数和cfg一致,默认416。
修改argument, filelist(all_label.txt地址,包含所有的label内容),
修改output_dir (输出文件地址),
修改num_clusters:聚类类数量

修改cfg,data,name文件

For yolo-obj.cfg:


for the training: batch=64 subdivisions=8
(bofore yolo) filters= num*(class+5)/3 (3处)
修改anchors,classes (3处)
参数理解:https://blog.csdn.net/weixin_42731241/article/details/81474920
https://blog.csdn.net/jinlong_xu/article/details/76375334,
if (batch_num < net.burn_in) return net.learning_rate * pow((float)batch_num / net.burn_in, net.power); ####(具体的内容:)
cp yolov3.cfg to yolo-obj.cfg 并修改 batch=64, subdivisions=8
修改max_batches to (classes2000), f.e. max_batches=6000 if you train for 3 classes
change line steps to 80% and 90% of max_batches, f.e. steps=4800,5400
change line classes=1 to your number of objects in each of 3 [yolo] layers:
change [filters=255] to filters=(classes + 5)xnum/3 in the 3 [convolutional] before each [yolo] layer. So if classes=1 then should be filters=18. If classes=2 then write filters=21. (Generally filters depends on the classes, coords and number of masks, i.e. filters=(classes + coords + 1)
, where mask is indices of anchors. If mask is absence, then filters=(classes + coords + 1)*num)

For person_obj.names:


Create obj.names in the directory with objects names - each in new line
如:
person
cat

For person_obj.data::


classes= 1
train = /home/wuhaotian/tiny_yolo/darknet/person_obj/train.txt
valid = /home/wuhaotian/tiny_yolo/darknet/person_obj/val.txt
names = /home/wuhaotian/tiny_yolo/darknet/person_obj/cfg/person_obj.names
backup = /home/wuhaotian/tiny_yolo/darknet/backup

下载预训练权重:


wget https://pjreddie.com/media/files/darknet53.conv.74\

开始训练:


./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74
./darknet detector train data/obj.data yolo-obj.cfg darknet53.conv.74 -gpus 0,1,2,3 -map

进行测试:


For normal Darknet:
./darknet detector test cfg/openimages.data cfg/yolov3-openimages.cfg yolov3-50000.weights test.jpg -thresh 0.25
./darknet detector map cfg/openimages.data cfg/yolov3-openimages.cfg yolov3-50000.weights -iou thresh 0.25


For AB:
进行Valid得到结果:
./darknet detector valid Person/yolov3.data Person/yolov3.cfg ~/darknet/Person/backup/yolov3.backup
进行Map计算:
./darknet detector map Person/yolov3.data Person/yolov3.cfg ~/darknet/Person/backup/yolov3_30000.weights -iou thresh 0.3
单独设置test集,需要把新目录test加入到utils.c里的repalce函数中
Relu 设置:activations.c -> activate array