目標檢測的評估過程(參考SSD300)
n_classes = 20+1(背景)
1.對網路的輸出進行decode
(batch, n_boxes_total, n_classes + 4 + 8)---->(batch, 200, 6)
2。將整個資料集的預測結果寫成一個巢狀list
(batch, 200, 6)—>result =[[],[],[],[]…],輸出一個巢狀list,21類。每一個裡面append((image_id, confidence, xmin, ymin, xmax, ymax))。最終得到整個資料集的結果。
for batch in batch_num: batch_X, batch_image_ids, batch_eval_neutral, batch_inverse_transforms, batch_orig_labels = next(generator)#生成器yield一批次資料 y_pred = net.predict(batch_X) y_predict = decode(y_predit) for k, batch_item in enumerate(y_pred): image_id = batch_image_ids[k] for box in batch_item: class_id = int(box[class_id_pred]) # Round the box coordinates to reduce the required memory. if round_confidences: confidence = round(box[conf_pred], round_confidences) else: confidence = box[conf_pred] xmin = round(box[xmin_pred], 1) ymin = round(box[ymin_pred], 1) xmax = round(box[xmax_pred], 1) ymax = round(box[ymax_pred], 1) prediction = (image_id, confidence, xmin, ymin, xmax, ymax) # Append the predicted box to the results list for its class. results[class_id].append(prediction)
3.計算gt個數---->{ndarray}[0,…],size:(21,)
4.得到TP = [[],[]…] ,FP = [[],[]…],cumulative_true_pos=[[],[]…],cumulative_true_neg=[[],[]…]
for class in range(1, self.n_classes + 1):
將label化成字典{img_id:(array())}
將predict[class]按置信度從大到小排
for i in predict[class]:
…
得到一個預測框
先通過預測框的img_id尋找出這張照片
然後通過預測框的類選出符合的gt框
通過iou選出最匹配的gt框(匹配過gt,不再匹配,將這種情況的預測框視為FP)
5.由cumulative_true_pos=[[],[]…],cumulative_true_neg=[[],[]…] 很容易得到cumulative_precisions=[[],[]…],cumulative_recall = [[],[]…]
6.計算AP
從小到大取11個point,作為recall的閾值,得到相應的pricise,取最大的一個,計算11個的平均值
7.計算map
求20類的平均值