【深度學習】深度學習中IU、IoU(Intersection over Union)的概念理解以及python程式實現
IoU(Intersection over Union)
Intersection over Union是一種測量在特定資料集中檢測相應物體準確度的一個標準。我們可以在很多物體檢測挑戰中,例如PASCAL VOC challenge中看多很多使用該標準的做法。
通常我們在 HOG + Linear SVM object detectors 和 Convolutional Neural Network detectors (R-CNN, Faster R-CNN, YOLO, etc.)中使用該方法檢測其效能。注意,這個測量方法和你在任務中使用的物體檢測演算法沒有關係。
IoU是一個簡單的測量標準,只要是在輸出中得出一個預測範圍(bounding boxex)的任務都可以用IoU來進行測量。為了可以使IoU用於測量任意大小形狀的物體檢測,我們需要:
1、 ground-truth bounding boxes(人為在訓練集影象中標出要檢測物體的大概範圍);
2、我們的演算法得出的結果範圍。
也就是說,這個標準用於測量真實和預測之間的相關度,相關度越高,該值越高。
如下圖:
下圖展示了ground-truth和predicted的結果,綠色標線是人為標記的正確結果,紅色標線是演算法預測出來的結果,IoU要做的就是在這兩個結果中測量演算法的準確度。
如上圖,很簡單,IoU相當於兩個區域重疊的部分除以兩個區域的集合部分得出的結果。
一般來說,這個score > 0.5 就可以被認為一個不錯的結果了。
##python程式實現
def bb_intersection_over_union(boxA, boxB): # determine the (x, y)-coordinates of the intersection rectangle xA = max(boxA[0], boxB[0]) yA = max(boxA[1], boxB[1]) xB = min(boxA[2], boxB[2]) yB = min(boxA[3], boxB[3]) # compute the area of intersection rectangle interArea = (xB - xA + 1) * (yB - yA + 1) # compute the area of both the prediction and ground-truth # rectangles boxAArea = (boxA[2] - boxA[0] + 1) * (boxA[3] - boxA[1] + 1) boxBArea = (boxB[2] - boxB[0] + 1) * (boxB[3] - boxB[1] + 1) # compute the intersection over union by taking the intersection # area and dividing it by the sum of prediction + ground-truth # areas - the interesection area iou = interArea / float(boxAArea + boxBArea - interArea) # return the intersection over union value return iou
##後記
IoU在FCN中稱為IU,初看Fully Convolutional Networks for Semantic Segmentation論文,其中的IU概念沒有能理解,其實那裡的IU也就是IoU,檢測物體輪廓不一定非得是方框,也可以是沿著物體的邊線:
在實際的任務中,根據不同的任務要求來寫不同具體實現的檢測方法,但說白了其實都是IoU或者IU。
另外mean IU指的是不同類別識別準確度的平均值,比如一幅圖中要識別三個物體,mean IU就是三個物體分別準確度加起來的平均值。
####參考資料:
1、https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/
2、https://stackoverflow.com/questions/25349178/calculating-percentage-of-bounding-box-overlap-for-image-detector-evaluation/42874377#42874377
3、https://stackoverflow.com/questions/25349178/calculating-percentage-of-bounding-box-overlap-for-image-detector-evaluation/42874377#42874377
原文地址: