def clip_boxes(boxes, im_shape):
    """
    Clip boxes to image boundaries.
    :param boxes: [N, 4* num_classes]
    :param im_shape: tuple of 2
    :return: [N, 4* num_classes]
    """
    if DEBUG:
        print("clip boxes shape:", boxes.shape)
    # x1 >= 0
    boxes[:, 0] = np.maximum(np.minimum(boxes[:, 0], im_shape[1]), 0)
    # y1 >= 0
    boxes[:, 1] = np.maximum(np.minimum(boxes[:, 1], im_shape[0]), 0)
    # x2 < im_shape[1]
    boxes[:, 2] = np.maximum(np.minimum(boxes[:, 2], im_shape[1]), 0)
    # y2 < im_shape[0]
    boxes[:, 3] = np.maximum(np.minimum(boxes[:, 3], im_shape[0]), 0)
    return boxes
Clip boxes to image boundaries.
:param boxes: [N, 4* num_classes]
:param im_shape: tuple of 2
:return: [N, 4* num_classes]
tests/unittest/ops/test_proposal.py