def calc_iou(bboxes1, bboxes2, bbox_mode='xywh'):
    assert ((len(bboxes1.shape) == 2) and (bboxes1.shape[1] == 4))
    assert ((len(bboxes2.shape) == 2) and (bboxes2.shape[1] == 4))
    bboxes1 = bboxes1.copy()
    bboxes2 = bboxes2.copy()
    if (bbox_mode == 'xywh'):
        bboxes1[:, 2:] += bboxes1[:, :2]
        bboxes2[:, 2:] += bboxes2[:, :2]
    (x11, y11, x12, y12) = np.split(bboxes1, 4, axis=1)
    (x21, y21, x22, y22) = np.split(bboxes2, 4, axis=1)
    xA = np.maximum(x11, np.transpose(x21))
    yA = np.maximum(y11, np.transpose(y21))
    xB = np.minimum(x12, np.transpose(x22))
    yB = np.minimum(y12, np.transpose(y22))
    interArea = (np.maximum(((xB - xA) + 1e-09), 0) * np.maximum(((yB - yA) + 1e-09), 0))
    boxAArea = (((x12 - x11) + 1e-09) * ((y12 - y11) + 1e-09))
    boxBArea = (((x22 - x21) + 1e-09) * ((y22 - y21) + 1e-09))
    iou = (interArea / ((boxAArea + np.transpose(boxBArea)) - interArea))
    return iou
def calc_iou(bboxes1, bboxes2, bbox_mode='xywh'):
    assert ((len(bboxes1.shape) == 2) and (bboxes1.shape[1] == 4))
    assert ((len(bboxes2.shape) == 2) and (bboxes2.shape[1] == 4))
    bboxes1 = bboxes1.copy()
    bboxes2 = bboxes2.copy()
    if (bbox_mode == 'xywh'):
        bboxes1[:, 2:] += bboxes1[:, :2]
        bboxes2[:, 2:] += bboxes2[:, :2]
    (x11, y11, x12, y12) = np.split(bboxes1, 4, axis=1)
    (x21, y21, x22, y22) = np.split(bboxes2, 4, axis=1)
    xA = np.maximum(x11, np.transpose(x21))
    yA = np.maximum(y11, np.transpose(y21))
    xB = np.minimum(x12, np.transpose(x22))
    yB = np.minimum(y12, np.transpose(y22))
    interArea = (np.maximum(((xB - xA) + 1e-09), 0) * np.maximum(((yB - yA) + 1e-09), 0))
    boxAArea = (((x12 - x11) + 1e-09) * ((y12 - y11) + 1e-09))
    boxBArea = (((x22 - x21) + 1e-09) * ((y22 - y21) + 1e-09))
    iou = (interArea / ((boxAArea + np.transpose(boxBArea)) - interArea))
    return iou