Skip to content

Improve error message for RandomCrop #2809

@vfdev-5

Description

@vfdev-5

🚀 Feature

In case if we apply RandomCrop(256) on images smaller than 256, current error message does not provide the information about size mismatch

import torchvision.transforms as T

t = T.RandomCrop(224)
t(torch.randint(0, 256, size=(3, 32, 32), dtype=torch.uint8))
> 
  File "/user/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 575, in forward
    i, j, h, w = self.get_params(img, self.size)
  File "/user/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 538, in get_params
    i = torch.randint(0, h - th + 1, size=(1, )).item()
RuntimeError: random_ expects 'from' to be less than 'to', but got from=0 >= to=-191

It would be nice to have a more user-friendly error message if h - th + 1 < 0 saying that we have a size mismatch.

cc @vfdev-5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions