ptrblck:

transforms.CenterCrop(50)(x)



Dear,
CenterCrop has different behaviour for PIL and tensor image.  In case of PIL image, it pads the image, while for tensor, it crops incorrectly[Checked code, it just computes offset(which are negative) and uses tensor indexing to extract the crop area which is incorrect.
For RandomCrop, api behaviour is consistent for both PIL and np.array for default arguments.
The code to reproduce CenterCrop inconsistency with output:-
pil_x = TF.to_pil_image(torch.randn(3, 24, 24))
transforms.CenterCrop(50)(pil_x).size
(50, 50)
tensor_x = torch.randn(3, 24, 24)
transforms.CenterCrop(50)(tensor_x).shape
torch.Size([3, 12, 12])
transforms.RandomCrop(50)(pil_x).size
Traceback (most recent call last):
  File "/home/skhanduja/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/203.6682.179/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/home/skhanduja/miniconda3/envs/wsss/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/skhanduja/miniconda3/envs/wsss/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 585, in forward
    i, j, h, w = self.get_params(img, self.size)
  File "/home/skhanduja/miniconda3/envs/wsss/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 541, in get_params
    raise ValueError(
ValueError: Required crop size (50, 50) is larger then input image size (24, 24)
transforms.RandomCrop(50)(tensor_x).size
Traceback (most recent call last):
  File "/home/skhanduja/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/203.6682.179/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/home/skhanduja/miniconda3/envs/wsss/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/skhanduja/miniconda3/envs/wsss/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 585, in forward
    i, j, h, w = self.get_params(img, self.size)
  File "/home/skhanduja/miniconda3/envs/wsss/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 541, in get_params
    raise ValueError(
ValueError: Required crop size (50, 50) is larger then input image size (24, 24)

Posting here so others who come here, dont make the mistake. Also, will it be alright if I add GITHUB Issue for this?
P.S. Congrats on 10k replies on forum. 
Update - The issue link is Inconsistent API for tensor and PIL image for CenterCrop · Issue #3297 · pytorch/vision · GitHub 8