def clip_boxes_to_image(boxes, height, width):
    """Clip an array of boxes to an image with the given height and width."""
    if boxes.numel() > 0:
        boxes[:, 0].clamp_(min=0, max=width - 1)
        boxes[:, 1].clamp_(min=0, max=height - 1)
        boxes[:, 2].clamp_(min=0, max=width - 1)
        boxes[:, 3].clamp_(min=0, max=height - 1)
    return boxes