目标检测中的mAP

mAP(mean Average Precision)主要用于度量Faster-RCNN、SSD等目标检测算法的准确性。表示不同召回率下最大准确率的平均值。

准确率:表示预测的正确性
召回率:表示寻找正样本的能力

用公式表示的话:
TP:True Positive //正样本且标注为正样本
FP:False Positive //正样本但标注为负样本
TN:True Negitive //负样本但标注为正样本
FN:False Negtive //负样本且标注为负样本

准确率:precision=TPTP+FP准确率: precision=\frac{TP}{TP + FP}:precision=TP+FPTP
召回率:recall=TPTP+FN召回率: recall=\frac{TP}{TP + FN}:recall=TP+FNTP

Fscore=2∗precision∗recallprecision+recallFscore = 2 * \frac{precision * recall}{precision + recall}Fscore=2precision+recallprecisionrecall

### 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、付费专栏及课程。

余额充值