def compute_iou()

in phosa/utils/bbox.py [0:0]


def compute_iou(bbox1, bbox2):
    """
    Computes Intersection Over Union for two boxes.

    Args:
        bbox1 (np.ndarray or torch.Tensor): (x1, y1, x2, y2).
        bbox2 (np.ndarray or torch.Tensor): (x1, y1, x2, y2).
    """
    a1 = compute_area(bbox1)
    a2 = compute_area(bbox2)
    if isinstance(bbox1, np.ndarray):
        lt = np.maximum(bbox1[:2], bbox2[:2])
        rb = np.minimum(bbox1[2:], bbox2[2:])
        wh = np.clip(rb - lt, a_min=0, a_max=None)
    else:
        stack = torch.stack((bbox1, bbox2))
        lt = torch.max(stack[:, :2], 0).values
        rb = torch.min(stack[:, 2:], 0).values
        wh = torch.clamp_min(rb - lt, 0)
    inter = wh[0] * wh[1]
    return inter / (a1 + a2 - inter)