Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions test/test_transforms_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3758,12 +3758,18 @@ def test_transform_errors_warnings(self):
with pytest.raises(ValueError, match="provide only two dimensions"):
transforms.RandomResizedCrop(size=(1, 2, 3))

with pytest.raises(TypeError, match="Scale should be a sequence"):
with pytest.raises(TypeError, match="Scale should be a sequence of two floats."):
transforms.RandomResizedCrop(size=self.INPUT_SIZE, scale=123)

with pytest.raises(TypeError, match="Ratio should be a sequence"):
with pytest.raises(TypeError, match="Ratio should be a sequence of two floats."):
transforms.RandomResizedCrop(size=self.INPUT_SIZE, ratio=123)

with pytest.raises(TypeError, match="Ratio should be a sequence of two floats."):
transforms.RandomResizedCrop(size=self.INPUT_SIZE, ratio=[1, 2, 3])

with pytest.raises(TypeError, match="Scale should be a sequence of two floats."):
transforms.RandomResizedCrop(size=self.INPUT_SIZE, scale=[1, 2, 3])

for param in ["scale", "ratio"]:
with pytest.warns(match="Scale and ratio should be of kind"):
transforms.RandomResizedCrop(size=self.INPUT_SIZE, **{param: [1, 0]})
Expand Down
8 changes: 4 additions & 4 deletions torchvision/transforms/v2/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ def __init__(
super().__init__()
self.size = _setup_size(size, error_msg="Please provide only two dimensions (h, w) for size.")

if not isinstance(scale, Sequence):
raise TypeError("Scale should be a sequence")
if not isinstance(ratio, Sequence):
raise TypeError("Ratio should be a sequence")
if not isinstance(scale, Sequence) or len(scale) != 2:
raise TypeError("Scale should be a sequence of two floats.")
if not isinstance(ratio, Sequence) or len(ratio) != 2:
raise TypeError("Ratio should be a sequence of two floats.")
if (scale[0] > scale[1]) or (ratio[0] > ratio[1]):
warnings.warn("Scale and ratio should be of kind (min, max)")

Expand Down