YOLO(YOU ONLY LOOK ONCE)
1.文章概要
用于目標檢測(Object Detection)任務,可以一次性完成對象的檢測和分類(Classfication)。檢測速度能達到50幀(FPS)以上,mAP(mean average precision)在VOC達到70%以上。
上面解決的方法是相對于Faster RCNN這類檢測算法來說的,同類的算法還有SSD(Single Shot MultiBox Detector),為何名稱不縮寫成SSMD。。。
2.基本思路
把圖像分成SxS個格子,如果一個目標落在某個格子中,那么就由該格子負責預測這個目標,每個格子預測B個Box,每個預測有五個參數confidence,x,y,w,h。
x,y:目標中心坐標
w,h:目標長寬
除了檢測目標的外接矩形外,還要檢測目標類別。
預測值是一個SxSx(Bx5+C)的tensor(張量)。
在VOC數據集上S取7,B取2,C為20。
C為類別數量。
這里顯然是存在一些缺陷的,最明顯的例子就是當兩個物體在一個格子內時就沒法同時檢測這兩個目標了(畢竟后面的分類只能有一種)
![Upload Paste_Image.png failed. Please try again.]
訓練圖像大小問題?
被統一處理成416*416
關于圖像大小處理的代碼
3.代碼實現
void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int flip, float dx, float dy, float sx, float sy)
{
char labelpath[4096];
find_replace(path, "images", "labels", labelpath);
find_replace(labelpath, "JPEGImages", "labels", labelpath);
find_replace(labelpath, ".jpg", ".txt", labelpath);
find_replace(labelpath, ".png", ".txt", labelpath);
find_replace(labelpath, ".JPG", ".txt", labelpath);
find_replace(labelpath, ".JPEG", ".txt", labelpath);
int count = 0;
box_label *boxes = read_boxes(labelpath, &count);
randomize_boxes(boxes, count);
correct_boxes(boxes, count, dx, dy, sx, sy, flip);
float x,y,w,h;
int id;
int i;
for (i = 0; i < count; ++i) {
x = boxes[i].x;
y = boxes[i].y;
w = boxes[i].w;
h = boxes[i].h;
id = boxes[i].id;
if (w < .005 || h < .005) continue;
int col = (int)(x*num_boxes);
int row = (int)(y*num_boxes);
x = x*num_boxes - col;
y = y*num_boxes - row;
int index = (col+row*num_boxes)*(5+classes);
if (truth[index]) continue;
truth[index++] = 1;
if (id < classes) truth[index+id] = 1;
index += classes;
truth[index++] = x;
truth[index++] = y;
truth[index++] = w;
truth[index++] = h;
}
free(boxes);
}
上面這段代碼用來構建目標值。從代碼中可以明顯開除如果某個格子內有多個目標是無法完成檢測任務的。
nms算法
Paste_Image.png
segmentation fault
如在把names改成中文,會出現segmentation fault。代碼在圖像上繪制文字,采用的是貼圖的方式,也就是它只有10個數字和26個字母的圖像,對于其它文字就不能繪制。