检测评价函数 intersection-over-union(IoU)

宁静致远
4周前 阅读 105 点赞 3

在目标检测的评价体系中,有一个参数叫做 IoU,简单而言就是模型产生的目标区域与原来标记区域的交叠率。即检测结果区域(Detection Result)与真值区域(Ground Truth)的交集比上它们的并集,其计算表达式为:

IoU=DetectionResultGroundTruthDetectionResultGroundTruthIoU=\frac{DetectionResult \cap GroundTruth}{DetectionResult \cup GroundTruth}

图示

DR = Detection Result;GT = Ground Truth;

实现(Python)

def IoU(frame_DR, framw_GT):"""
    计算两矩形的IoU,传入为均为矩形对角线两端点坐标(x1,y1,x2,y2)
    """
    x1 = frame_DR[0]
    y1 = frame_DR[1]
    width1 = frame_DR[2] - frame_DR[0]
    height1 = frame_DR[3] - frame_DR[1]


    x2 = framw_GT[0]
    y2 = framw_GT[1]
    width2 = framw_GT[2] - framw_GT[0]
    height2 = framw_GT[3] - framw_GT[1]


    startx = min(x1, x2)
    endx = max(x1 + width1, x2 + width2)
    width = width1 + width2 - (endx - startx)


    starty = min(y1, y2)
    endy = max(y1 + height1, y2 + height2)
    height = height1 + height2 - (endy - starty)


    if width <= 0 or height <= 0:
        iou = 0  # 重叠率为 0else:
        area = width * height  # 两矩形重叠面积
        area1 = width1 * height1
        area2 = width2 * height2
        iou = area * 1. / (area1 + area2 - area)
    return iou, frame_DR, framw_GT


| 3
登录后可评论,马上登录吧~
评论 ( 0 )

还没有人评论...