def box_clamp(boxes, x_min, y_min, x_max, y_max):
    """Clamp boxes.

    Args:
      boxes: (tensor) bounding boxes of (x_min, y_min, x_max, y_max), sized [N, 4].
      x_min: (number) min value of x.
      y_min: (number) min value of y.
      x_max: (number) max value of x.
      y_max: (number) max value of y.

    Returns:
      (tensor) clamped boxes.
    """
    boxes[:, 0].clamp_(min=x_min, max=x_max)
    boxes[:, 1].clamp_(min=y_min, max=y_max)
    boxes[:, 2].clamp_(min=x_min, max=x_max)
    boxes[:, 3].clamp_(min=y_min, max=y_max)
    return boxes