import torch


def _mask_borders(
  masks: torch.Tensor,
  clip_border: int
) -> torch.Tensor:
  """Masking left/right/top/down borders by setting `masks` to False

  Args:
    masks (torch.Tensor): mask in shape (..., h, w). torch.bool
    clip_border (int): number of border pixels to mask.

  Returns:
    torch.Tensor: new mask in shape (..., h, w). torch.bool
  """
  assert torch.is_tensor(masks), \
    f"`masks` should be a torch.Tensor, got {type(masks)}"
  assert len(masks.shape) >= 2, "rank of `masks` should be greater than 2"
  # clip h
  masks[..., :clip_border, :] = False
  masks[..., -clip_border:, :] = False
  # clip w
  masks[..., :clip_border] = False
  masks[..., -clip_border:] = False
  return masks