def box_iou(boxes1: "torch.Tensor", boxes2: "torch.Tensor"):
    """
    From DETR source: https://github.com/facebookresearch/detr
    (detr/util/box_ops.py)
    """
    from torchvision.ops.boxes import box_area

    area1 = box_area(boxes1)
    area2 = box_area(boxes2)

    l_t = torch.max(boxes1[:, None, :2], boxes2[:, :2])  # [N,M,2]
    r_b = torch.min(boxes1[:, None, 2:], boxes2[:, 2:])  # [N,M,2]

    w_h = (r_b - l_t).clamp(min=0)  # [N,M,2]
    inter = w_h[:, :, 0] * w_h[:, :, 1]  # [N,M]

    union = area1[:, None] + area2 - inter

    iou = inter / union
    return iou, union

    From DETR source: https://github.com/facebookresearch/detr
    (detr/util/box_ops.py)
    
art/estimators/object_detection/detr.py