import torch


def crop_box(x: torch.Tensor, bbox_XYXY):
    """
        Crops x by bbox_XYXY. 
    """
    assert len(x.shape) == 3
    x0, y0, x1, y1 = bbox_XYXY
    x0 = max(x0, 0)
    y0 = max(y0, 0)
    x1 = min(x1, x.shape[2])
    y1 = min(y1, x.shape[1])
    return x[:, y0:y1, x0:x1]