目標檢查評價指標mAP
連線:
1.混淆矩陣
真實值(true) 真實值(false)
預測值(true)TP (True Positive) FP(False Positive)
預測值(false)FN(False Negative) TN(True Negative)
recall = TP/(FN+TP) 「查全率」:所有的正樣本是不是都被檢測出來了。比如在腫瘤預測場景中,要求模型有更高的recall,不能放過每一個腫瘤
precision = TP/(TP+FP)「查準率] :在所有檢測出的正樣本中是不是實際都為正樣本。比如在垃圾郵件判斷等場景中,要求有更高的precision,確保放到回收站的都是垃圾郵件
ImageNet的評價標準。但具體到單個類別,如果recall比較高,但precision較低,比如大部分的汽車都被識別出來了,但把很多卡車也誤識別為了汽車,這時候對應一個原因。如果recall較低,precision較高,比如檢測出的飛機結果很準確,但是有很多的飛機沒有被識別出來,這時候又有一個原因
在mAP計算中
1.幹活的時候confidence選擇比較高,一般來說為0.5,0.3
2.測量mAP的是時候比較低一般為0.001,0.01之類的非常小(統一標準,保留多一點框)
手寫mAP
第一步match_table
match_table格式為
[confidence(置信度), matched_iou(類間iou), matched_groundtruth_index(最匹配真是圖id), image_id(圖片id)] 程式碼如下def nms_as_class(bboxes, threshold, class_index=-1View Code, confidence_index=-2): boxasclass = {} for box in bboxes: classes = box[class_index] if classes not in boxasclass: boxasclass[classes] = [] boxasclass[classes].append(box) output = [] for key in boxasclass: result = nms(boxasclass[key], threshold, confidence_index) output.extend(result)return output
# 5.計算[email protected]的precision、recall曲線
* 0.5指IoU的閾值是0.5,如果需要計算[email protected],直接指定閾值0.75即可
* 當某一個detection的最優匹配的IoU > threshold時,被認為檢測成功,
* 對應的groundtruth如果第一次出現,則該detection被認為是true_positive,否則是false_positive
* 當選中一個true_positive時,其對應的groundtruth設定為見過(seen),以後任何detection見到他都不能夠匹配為true_positive
* Recall的計算公式為:
Recall={TP}/{TP + FN} = {TP}/ground truths}
* Precision的計算公式為:
Precision={TP}/{TP + FP} = {TP}/{\#detections}
* 對於檢測任務而言,真實值只有Positive,沒有Negative。預測值只有Positive,沒有Negative
- 也因此,咱們只有FN、FP、TP沒有TN
- 所以,TP + FN,就是ground truths的數量
- 所以,TP + FP,就是detections的數量
程式碼如下
# 計算AP@0.5 代表的含義是iou閾值為0.5的時候Precision,Recall值 # 如果有出現的框我們只匹配一次 iou_threshold = 0.5 num_detection = len(matched_table) true_positive = np.zeros((num_detection,)) # 因為不是全域性唯一matched_index,每個圖片對應一些match_index groundtruth_seen_map = {item[3]: set() for item in matched_table} for detection_index in range(num_detection): confidence, iou_value, match_index, image_id = matched_table[0] if iou_value >= iou_threshold: groundtruth_seen_map_set = groundtruth_seen_map[image_id] if match_index not in groundtruth_seen_map_set: groundtruth_seen_map_set.add(match_index) true_positive[detection_index] = 1 num_predicts = np.arange(1, len(true_positive) + 1) accumulate_true_positive = np.cumsum(true_positive) precision = accumulate_true_positive / num_predicts recall = accumulate_true_positive / sum_groundtruthView Code
------------恢復內容結束------------