def clip_boxes(boxes, im_shape):
    """
    Clip boxes to image boundaries.
    :param boxes: [N, 4]
    :param im_shape: tuple of 2, [h, w]
    :return: [N, 4]
    """
    # x1 >= 0
    boxes[:, 0] = np.clip(boxes[:, 0], 0, im_shape[1] - 1)
    # y1 >= 0
    boxes[:, 1] = np.clip(boxes[:, 1], 0, im_shape[0] - 1)
    # x2 < im_shape[1]
    boxes[:, 2] = np.clip(boxes[:, 2], 1, im_shape[1])
    # y2 < im_shape[0]
    boxes[:, 3] = np.clip(boxes[:, 3], 1, im_shape[0])
    return boxes

    Clip boxes to image boundaries.
    :param boxes: [N, 4]
    :param im_shape: tuple of 2, [h, w]
    :return: [N, 4]
    
ppdet/data/crop_utils/chip_box_utils.py