You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

对比同一图像两组Ground Truth,计算FP、FN、TP并验证标注覆盖性

图像标注验证与指标统计方案

核心定义

先明确统计指标的含义:

  • True Positive (TP):新标注(红框)与原Ground Truth(绿框)匹配成功的标注(即新标注正确覆盖了原有目标)
  • False Positive (FP):新标注中无对应原Ground Truth的标注(即误标了不存在的目标)
  • False Negative (FN):原Ground Truth中未被新标注匹配到的标注(即漏标了原有目标)

匹配规则

判断两个标注框是否匹配,通用标准是交并比(IoU):计算红框与绿框的IoU值,当IoU ≥ 设定阈值(常规取0.5,可按需调整)时,判定为一对匹配标注。

单张图统计步骤

  1. 整理集合:把原绿框全部列出为集合G,数量记为len(G);新红框列出为集合D,数量记为len(D)
  2. 匹配计数:
    • 遍历每个绿框,找到对应IoU达标红框,每匹配成功一对,TP加1,同时从D中移除该红框(避免重复匹配)
    • 遍历结束后,G中未匹配的绿框数量即为FN;D中剩余未匹配的红框数量即为FP
  3. 验证覆盖性:若FN=0,说明新标注包含全部原Ground Truth;否则存在漏标

示例演示

假设:

  • 原绿框共5个,新红框共6个
  • 匹配成功4对(TP=4)
  • 剩余1个绿框未匹配(FN=1)
  • 剩余2个红框未匹配(FP=2)
    结果:新标注未覆盖全部原标注,最终指标为TP=4、FP=2、FN=1

工具辅助脚本(可选)

如果不想手动计算IoU,可使用以下Python脚本快速统计:

def calculate_iou(box1, box2):
    # 框格式:[x1, y1, x2, y2](左上角、右下角坐标)
    x1 = max(box1[0], box2[0])
    y1 = max(box1[1], box2[1])
    x2 = min(box1[2], box2[2])
    y2 = min(box1[3], box2[3])
    
    intersection = max(0, x2 - x1) * max(0, y2 - y1)
    area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
    area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
    union = area1 + area2 - intersection
    
    return intersection / union if union != 0 else 0

# 替换为你的标注框数据
ground_truth = [[10,10,50,50], [60,60,100,100]]
new_annotations = [[12,12,52,52], [65,65,105,105], [110,110,150,150]]
iou_threshold = 0.5

tp_count = 0
matched_new_indices = set()

# 匹配原框与新框
for gt_box in ground_truth:
    for idx, new_box in enumerate(new_annotations):
        if idx not in matched_new_indices and calculate_iou(gt_box, new_box) >= iou_threshold:
            tp_count += 1
            matched_new_indices.add(idx)
            break

fn_count = len(ground_truth) - tp_count
fp_count = len(new_annotations) - len(matched_new_indices)

print(f"TP: {tp_count}, FP: {fp_count}, FN: {fn_count}")

内容的提问来源于stack exchange,提问作者Kapil Dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 13:55:28