官网yolov1:http://pjreddie.com/darknet/yolov1/git
官网yolov2:http://pjreddie.com/darknet/yolo/github
github yolo:https://github.com/pjreddie/darknetide
yolo训练要有本身的一套方式,先说说label要怎么弄。函数
首先看看标签和数据的格式.net
数据放在images中,这个文件夹名字能够随便起,可是注意,labels这个文件夹必定不能改。这个yolo会自动找到这个文件夹里面标好的数据的。code
而后进入labels这个文件夹blog
咱们分析一下这个文件夹里面的内容图片
标签的格式是:ip
类别 框的中心点X方向/图像宽 框的中心点Y方向/图像高 框宽/图像宽 框高/图像高 class_number box2_x1_ratio box2_y1_ratio box2_width_ratio box2_height_ratio
具体计算看一看scripts/voc_label.py的源码get
# size :width height box: xmin xmax ymin ymax def convert(size, box): dw = 1./size[0] dh = 1./size[1] x = (box[0] + box[1])/2.0 y = (box[2] + box[3])/2.0 w = box[1] - box[0] h = box[3] - box[2] x = x*dw w = w*dw y = y*dh h = h*dh return (x,y,w,h)
而后要改yolo.c文件中的类别数目,修改train.txt路径到本身的train.txt,**注意下,train.txt里面只须要写图片的路径就能够了,每行一张图片路径,用的是绝对路径,相对路径尚未用过,不知道行不行。
char *train_images = "/data/voc/train.txt"; char *backup_directory = "/home/pjreddie/backup/";
而后找到这个函数
draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, alphabet, CLASSNUM);
最后的classnum改为本身的类型数目。
yolo_kernels.cu文件中 找到这个函数
draw_detections(det, l.side*l.side*l.n, demo_thresh, boxes, probs, voc_names, voc_labels, CLS_NUM);
改变最后的cls_num为本身的类型数目。
最后要改的就是yolo2.cfg 或者是yolo.cfg,看你用哪一个,不过这个都是yolov1的。
切记一点,在两个文件的最末端
[connected] output= 931 activation=linear [detection] classes=4 coords=4 rescore=1 side=7 num=3 softmax=0 sqrt=1 jitter=.2
output 是须要从新计算的,若是不从新计算会报一个问题
Assertion `side*side*((1 + l.coords)*l.n + l.classes) == inputs' failed.
而这个output值的计算如上面这个错误
即 output = 7*7*((1+coords)*num+classes)
这个classes须要改为本身的类别数目。
若是要用yolov2的进行训练的话,那么须要从新计算最后一层的filter
[convolutional] size=1 stride=1 pad=1 filters=425 activation=linear [region] anchors = 0.738768,0.874946, 2.42204,2.65704, 4.30971,7.04493, 10.246,4.59428, 12.6868,11.8741 bias_match=1 classes=80 coords=4 num=5 softmax=1 jitter=.2 rescore=1 object_scale=5 noobject_scale=1 class_scale=1 coord_scale=1
filter的计算公式为
filters = num*(classes+coords+1)
去官网下载extraction.conv.weights,固然也能够本身从新计算extraction.conv.weights, 过程就不详细叙述了,能够去官网本身看看。最后就能够愉快的运行训练了。
./darknet yolo train cfg/yolov1/yolo2.cfg extraction.conv.weights
截图留念
最后给出一个不错的blog,YOLO2 如何fine tunning