mAP解释

AP用来处理目标检测问题,Precision和Recall只能处理分类问题。

mAP处理多目标问题,对AP进行简单平均。

 

mAP计算的两个参数

(1)IoU确定一个检测结果(Positive)是正确的(True)还是错误的(False)。

解释:1的confidence score所有结果都是预测框,IoU决定了label的值,也就决定了预测是否是对的。

IOU阈值可以人为确定= 0.5,COCO数据集的评估指标建议对不同的IoU阈值进行计算。

(2)置信度(confidence score)确定预测框是Positive还是 Negative。

解释:小于设定的置信度的结果都不认为是真。

必须用PASCAL VOC CHALLENGE的标准来解决问题,因为不同的模型置信度归一化或者说计算方法不同。

参考文章

1.性能指标(模型评估)之mAP

https://blog.youkuaiyun.com/u014203453/article/details/77598997

2.最完整的检测模型评估指标mAP计算指南(附代码)在这里!

https://blog.youkuaiyun.com/l7H9JA4/article/details/80745028

文章1对mAP的计算过程讲解较清晰,但是没指出怎么给出ground truth label,也就是没解释IoU起到的作用。

文章2给出了ground truth的解释:计算每个Positive预测框与ground truth的IoU值,并取最大的IoU值,认为该预测框检测到了。然后根据IoU阈值(VOC取0.5),得到label为1的检测框,剩下的都是label为0。

### mAP 的定义 mAP 是 mean of Average Precision 的缩写,表示平均精确度(Average Precision, AP)的均值。它是目标检测领域中用于衡量模型性能的重要指标[^3]。由于目标检测不仅涉及分类还涉及定位,传统的分类准确性(Accuracy)无法全面反映模型的表现,因此引入了 mAP 这一更加复杂的评价标准。 --- ### 查准率(Precision)和查全率(Recall) 为了更好地理解 mAP,需先了解 Precision 和 Recall: - **Precision (查准率)**:指的是预测为正类的样本中有多少是真正的正类。 \[ \text{Precision} = \frac{\text{True Positives}}{\text{True Positives} + \text{False Positives}} \] - **Recall (查全率)**:指的是所有真实正类中有多少被正确预测出来。 \[ \text{Recall} = \frac{\text{True Positives}}{\text{True Positives} + \text{False Negatives}} \] 这两个指标共同构成了 PR 曲线的基础[^3]。 --- ### 平均精确度(AP)的计算方法 对于某一特定类别,通过绘制 Precision-Recall (PR)曲线来计算该类别的 AP 值。具体步骤如下: 1. 预测结果按置信度(Confidence Score)降序排列。 2. 对每一个预测框,判断其是否为 True Positive 或 False Positive,基于预设的 IoU(Intersection over Union)阈值。 3. 计算不同召回率(Recall)下的精度(Precision),并形成 PR 曲线。 4. 使用数值积分法(如梯形法则)求解 PR 曲线下面积作为 AP 值[^1]。 某些数据集(如 COCO 数据集)会进一步扩展此定义,在不同的 IoU 阈值下分别计算 AP,并取这些 AP 的加权平均值。 --- ### 多类别场景下的 mAP 计算 在多类别目标检测任务中,针对每一类别独立计算其对应的 AP 值,随后将各类别 AP 取平均值得到最终的 mAP 值。例如,若有 \( N \) 类,则: \[ \text{mAP} = \frac{1}{N} \sum_{i=1}^{N} \text{AP}_i \] 其中,\( \text{AP}_i \) 表示第 \( i \) 类别的 AP 值[^4]。 需要注意的是,部分评估体系可能会考虑额外因素,例如对象尺寸分组或多种 IoU 阈值组合,从而得到更为严格的 mAP 定义。 --- ### 示例代码实现 以下是 Python 实现的一个简化版 mAP 计算逻辑: ```python def calculate_ap(precisions, recalls): """ Calculate the average precision given lists of precisions and recalls. Args: precisions (list): List of precision values at different thresholds. recalls (list): Corresponding list of recall values. Returns: float: The computed average precision value. """ ap = 0.0 previous_recall = 0.0 # Sort by increasing recall order sorted_indices = sorted(range(len(recalls)), key=lambda k: recalls[k]) precisions_sorted = [precisions[i] for i in sorted_indices] recalls_sorted = [recalls[i] for i in sorted_indices] for idx in range(1, len(sorted_indices)): delta_recall = recalls_sorted[idx] - previous_recall max_precision = max(precisions_sorted[:idx+1]) # Interpolate maximum precision ap += delta_recall * max_precision previous_recall = recalls_sorted[idx] return ap def calculate_map(ap_per_class): """ Compute Mean Average Precision from per-class APs. Args: ap_per_class (dict): Dictionary mapping class names to their respective AP scores. Returns: float: Final calculated mAP score across all classes. """ total_classes = len(ap_per_class) sum_aps = sum(ap_per_class.values()) map_score = sum_aps / total_classes if total_classes != 0 else 0.0 return map_score ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值