目标检测的评估过程(参考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类的平均值

你可能感兴趣的:(深度学习)