对于目标检测中mAP@0.5的理解

前言

一直不是很理解目标检测中的mAP是如何的,今天具体来写一下,加深一下理解。

mAP@0.5

mAP@0.5:mean Average Precision
通俗来说,就是给每一类分别计算AP,然后做mean平均。
那AP是什么呢,之前我一直以为是Average Precision,没错,就是平均精确度,可是这个怎么定义呢?

AP是Precision-Recall Curve(PRC)下面的面积!!!

在这里插入图片描述

PRC怎么看:先看平滑不平滑(蓝线明显好些),在看谁上谁下(同一测试集上),一般来说,上面的比下面的好(绿线比红线好)。

接下来来想一下Precision和Recall怎么定义。
之前都知道:

P r e c i s i o n = T P T P + F P Precision

### YOLOv11 mAP@0.5 的计算方法 对于YOLOv11模型,在特定IoU阈值(0.5)下计算平均精度均值(mAP),涉及几个关键步骤。首先,理解mAP的概念至关重要。mAP是指所有类别上平均精度(Average Precision, AP)的均值。而AP衡量的是某一类别的检测性能。 #### 平均精度 (AP) 为了获得某个类别的AP,需要先定义一系列不同的置信度阈值来过滤预测框,并针对每一个阈值计算查准率(Precision)和召回率(Recall)。随后,通过插值法得到这些点构成的一条P-R曲线下的面积即为该类目的AP[^1]。 #### 计算过程 当设定IoU阈值为0.5时: - **真阳性(True Positive)**:如果预测边界框与真实标注之间的交并比(IoU)大于等于0.5,则认为是一个正确的正样本。 - **假阴性(False Negative)** 和 **假阳性(False Positive)** 则分别表示未能成功匹配到任何GT box 或者错误标记为目标的情况。 基于上述分类标准统计各个类目在整个测试集上的TP/FP数量变化情况,进而可以构建出完整的P-R曲线用于后续分析。 最后一步就是求取所有类目标的AP之后再做一次简单平均就得到了最终想要的结果——`mAP@0.5`。 ```python def calculate_map_at_0_5(predictions, ground_truths): """ Calculate the mean average precision at IoU threshold of 0.5. Args: predictions: List of prediction bounding boxes and their scores per image. ground_truths: List of true bounding boxes per image. Returns: float: The calculated mAP value @ IoU=0.5. """ iou_threshold = 0.5 # Initialize variables to store results across all classes ap_per_class = {} for cls_id in unique_classes_in_data(): precisions, recalls = compute_precision_recall_for_class( predictions=predictions, ground_truths=ground_truths, class_index=cls_id, iou_threshold=iou_threshold ) # Compute interpolated precision/recall curve area under it as AP ap_value = voc_ap(precisions, recalls) ap_per_class[cls_id] = ap_value # Mean over all classes gives us final result map_result = sum(ap_per_class.values()) / len(unique_classes_in_data()) return map_result def voc_ap(recalls, precisions): """Compute VOC-style Average Precision from recall & precision lists.""" rec = np.concatenate(([0.], recalls, [1.])) pre = np.concatenate(([0.], precisions, [0.])) # Ensure decreasing order by reversing sort on precisions where there are ties in recalls for i in range(len(pre)-2,-1,-1): pre[i]=max(pre[i],pre[i+1]) indices = np.where(rec[:-1]!=rec[1:])[0]+1 ap=np.sum((rec[indices]-rec[indices-1])*pre[indices]) return ap ```
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zedjay_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值