ruijiege

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  346 随笔 :: 0 文章 :: 8 评论 :: 12万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
 

连接:

目标检测评价标准mAP - 知乎 (zhihu.com)

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=-1, 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
View Code
复制代码

 

# 5.计算AP@0.5的precision、recall曲线
* 0.5指IoU的阈值是0.5,如果需要计算AP@0.75,直接指定阈值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_groundtruth
View Code
复制代码

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

------------恢复内容结束------------

posted on   哦哟这个怎么搞  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2021-12-08 pycharm不能导入对应的模块
点击右上角即可分享
微信分享提示