Unverified Commit 1d6a259c authored by vfdev's avatar vfdev Committed by GitHub
Browse files

Fixed error condition in RandomCrop (#6548)

parent 112accf9
......@@ -1670,7 +1670,7 @@ def test_random_crop():
assert result.size(1) == height + 1
assert result.size(2) == width + 1
t = transforms.RandomCrop(48)
t = transforms.RandomCrop(33)
img = torch.ones(3, 32, 32)
with pytest.raises(ValueError, match=r"Required crop size .+ is larger than input image size .+"):
t(img)
......
......@@ -443,7 +443,7 @@ class RandomCrop(Transform):
if height < output_height:
height += 2 * (output_height - height)
if height + 1 < output_height or width + 1 < output_width:
if height < output_height or width < output_width:
raise ValueError(
f"Required crop size {(output_height, output_width)} is larger then input image size {(height, width)}"
)
......
......@@ -628,7 +628,7 @@ class RandomCrop(torch.nn.Module):
_, h, w = F.get_dimensions(img)
th, tw = output_size
if h + 1 < th or w + 1 < tw:
if h < th or w < tw:
raise ValueError(f"Required crop size {(th, tw)} is larger than input image size {(h, w)}")
if w == tw and h == th:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment