def boxes_iou(boxes1, boxes2):
    '''
    Compute iou

    Args:
        boxes1 (paddle.tensor) shape (N, 4)
        boxes2 (paddle.tensor) shape (M, 4)

    Return:
        (paddle.tensor) shape (N, M)
    '''
    area1 = box_area(boxes1)
    area2 = box_area(boxes2)

    lt = paddle.maximum(boxes1.unsqueeze(-2)[:, :, :2], boxes2[:, :2])
    rb = paddle.minimum(boxes1.unsqueeze(-2)[:, :, 2:], boxes2[:, 2:])

    wh = (rb - lt).astype("float32").clip(min=1e-9)
    inter = wh[:, :, 0] * wh[:, :, 1]

    union = area1.unsqueeze(-1) + area2 - inter + 1e-9

    iou = inter / union
    return iou, union

    Compute iou

    Args:
        boxes1 (paddle.tensor) shape (N, 4)
        boxes2 (paddle.tensor) shape (M, 4)

    Return:
        (paddle.tensor) shape (N, M)
    
ppdet/modeling/losses/sparsercnn_loss.py