YOLO 训练
2019獨角獸企業重金招聘Python工程師標準>>>
官網yolov1:http://pjreddie.com/darknet/yolov1/
官網yolov2:http://pjreddie.com/darknet/yolo/
github yolo:https://github.com/pjreddie/darknet
yolo訓練要有自己的一套方式,先說說label要怎么弄。
1 標簽和數據的格式
首先看看標簽和數據的格式
數據放在images中,這個文件夾名字可以隨便起,但是注意,labels這個文件夾一定不能改。這個yolo會自動找到這個文件夾里面標好的數據的。
然后進入labels這個文件夾
我們分析一下這個文件夾里面的內容
標簽的格式是:
類別 框的中心點X方向/圖像寬 框的中心點Y方向/圖像高 框寬/圖像寬 框高/圖像高 class_number box2_x1_ratio box2_y1_ratio box2_width_ratio box2_height_ratio具體計算看一看scripts/voc_label.py的源碼
# 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.0y = (box[2] + box[3])/2.0w = box[1] - box[0]h = box[3] - box[2]x = x*dww = w*dwy = y*dhh = h*dhreturn (x,y,w,h)2 修改yolo.c
然后要改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改成自己的類型數目。
3 修改yolo_kernels.cu
yolo_kernels.cu文件中 找到這個函數
draw_detections(det, l.side*l.side*l.n, demo_thresh, boxes, probs, voc_names, voc_labels, CLS_NUM);改變最后的cls_num為自己的類型數目。
4 修改cfg
最后要改的就是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=.2output 是需要重新計算的,如果不重新計算會報一個問題
Assertion `side*side*((1 + l.coords)*l.n + l.classes) == inputs' failed.而這個output值的計算如上面這個錯誤
- side=7
- l.coords = coords
- l.n = num
- l.classes = classes
即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=1object_scale=5 noobject_scale=1 class_scale=1 coord_scale=1filter的計算公式為
filters = num*(classes+coords+1)5 訓練
去官網下載extraction.conv.weights,當然也可以自己重新計算extraction.conv.weights, 過程就不詳細敘述了,可以去官網自己看看。最后就可以愉快的運行訓練了。
./darknet yolo train cfg/yolov1/yolo2.cfg extraction.conv.weights截圖留念
最后給出一個不錯的blog,YOLO2 如何fine tunning
轉載于:https://my.oschina.net/u/1046919/blog/801132
總結
- 上一篇: 数据库(Mysql)背后的数据结构-学习
- 下一篇: EJB 的理解