There may be some errors in the `torchvision.transforms.transfroms.RandomCrop`

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

Thanks for reporting the issue. It seems the check might need to be updated, as an invalid size by 1 will fail in the sampling step currently instead of the check:

t = transforms.RandomCrop(size=101)
t.get_params(torch.randn(3, 100, 100), (50, 50)) # works
t.get_params(torch.randn(3, 100, 100), (100, 100)) # works
t.get_params(torch.randn(3, 100, 100), (101, 101)) # fails in the sampling step
# > RuntimeError: random_ expects 'from' to be less than 'to', but got from=0 >= to=0
t.get_params(torch.randn(3, 100, 100), (102, 102)) # fails in the check
# > ValueError: Required crop size (102, 102) is larger then input image size (100, 100)

Would you mind creating an issue in GitHub so that it can be tracked and fixed?