官網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