In the method get_params of torchvision.transforms.transfroms.RandomCrop
def get_params(img: Tensor, output_size: Tuple[int, int]) → Tuple[int, int, int, int]:
w, h = F._get_image_size(img)
th, tw = output_size
if h + 1 < th or w + 1 < tw: # this may be changed to h < th or w < tw
raise ValueError(
“Required crop size {} is larger then input image size {}”.format((th, tw), (h, w))
)
if w == tw and h == th:
return 0, 0, h, w
i = torch.randint(0, h - th + 1, size=(1, )).item()
j = torch.randint(0, w - tw + 1, size=(1, )).item()
return i, j, th, tw