其他分享
首页 > 其他分享> > 交并比 iou

交并比 iou

作者:互联网

交并比

在判定预测框和真实框之间的准确度的时候,我们可以用iou进行量化,如下图,黑框为真实框,红框为预测框,

def box_iou(box, boxes):
    """

    :param box: [4,](x1,y1,x2,y2)
    :param boxes: [n,4]
    :return: [n]
    """
    # box 面积
    box_area = ((box[2] - box[0] + 1) * (box[3] - box[1] + 1))
    # boxs 面积 [n,]
    boxes_area = (boxes[:, 2] - boxes[:, 0] + 1) * (boxes[:, 3] - boxes[:, 1] + 1)
    # 重叠部分左上右下坐标
    xx1 = np.maximum(box[0], boxes[:, 0])
    yy1 = np.maximum(box[1], boxes[:, 1])
    xx2 = np.minimum(box[2], boxes[:, 2])
    yy2 = np.minimum(box[3], boxes[:, 3])

    # 重叠部分长宽
    w = np.maximum(0, xx2 - xx1 + 1)
    h = np.maximum(0, yy2 - yy1 + 1)
    # 计算重叠面积
    inter = w * h
    iou = inter / (box_area + boxes_area - inter + 1e-10)
    return iou

标签:box,area,iou,maximum,np,boxes,交并
来源: https://blog.csdn.net/xf8964/article/details/110282986