【机器学习】TP TN FP FN及IoU的关系

  • TP(True Positives): 真的正样本 = 【正样本 被正确分为 正样本】
  • TN(True Negatives): 真的负样本 = 【负样本 被正确分为 负样本】
  • FP(False Positives): 假的正样本 = 【负样本 被错误分为 正样本】
  • FN(False Negatives):假的负样本 = 【正样本 被错误分为 负样本】
    请添加图片描述
    Precision:预测正确的部分预测结果的比例
    Precision = TP TP + FP   \text{Precision}=\frac {\text{TP}} {\text{TP}+\text{FP}} \text{ } Precision=TP+FPTP 
    Recall:预测正确的部分GroundTruth的比例
    Recall = TP TP + FN   \text{Recall}=\frac {\text{TP}} {\text{TP}+\text{FN}} \text{ } Recall=TP+FNTP 
    IoU:交集与并集的比值
    IoU = TP TP + FP + FN \text{IoU}=\frac{\text{TP}}{\text{TP}+\text{FP}+\text{FN}} IoU=TP+FP+FNTP请添加图片描述
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是Python代码示例,用于计算目标检测中的True positive(TP)、False positive(FP)和False negative(FN): ```python def calculate_TP_FP_FN(pred_boxes, true_boxes, iou_thresh): # pred_boxes: 预测框的坐标,格式为[x_min, y_min, x_max, y_max] # true_boxes: 真实框的坐标,格式为[x_min, y_min, x_max, y_max] # iou_thresh: IOU阈值 TP = 0 FP = 0 FN = 0 # 对于每个预测框,找到与其IOU大于阈值的真实框 for i in range(len(pred_boxes)): iou_max = 0 match = -1 for j in range(len(true_boxes)): iou = calculate_iou(pred_boxes[i], true_boxes[j]) if iou > iou_thresh and iou > iou_max: iou_max = iou match = j # 如果找到了匹配的真实框,则计算TP if match != -1: TP += 1 true_boxes.pop(match) # 否则,计算FP else: FP += 1 # 计算未匹配的真实框数,即FN FN = len(true_boxes) return TP, FP, FN def calculate_iou(box1, box2): # box1和box2的格式为[x_min, y_min, x_max, y_max] 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) area_box1 = (box1[2] - box1[0]) * (box1[3] - box1[1]) area_box2 = (box2[2] - box2[0]) * (box2[3] - box2[1]) union = area_box1 + area_box2 - intersection iou = intersection / union return iou ``` 其中,`calculate_iou`函数用于计算两个框之间的IOU,`calculate_TP_FP_FN`函数用于计算TPFPFN。其中,输入的预测框和真实框均为坐标格式,即左上角和右下角的坐标值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Quentin_HIT

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

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

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

打赏作者

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

抵扣说明:

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

余额充值