Unverified Commit 69dc971e authored by vfdev's avatar vfdev Committed by GitHub
Browse files

Added sizes check and a test (#2816)

parent 3f222e81
......@@ -298,6 +298,11 @@ class Tester(unittest.TestCase):
self.assertEqual(result.size(1), height + 1)
self.assertEqual(result.size(2), width + 1)
t = transforms.RandomCrop(48)
img = torch.ones(3, 32, 32)
with self.assertRaisesRegex(ValueError, r"Required crop size .+ is larger then input image size .+"):
t(img)
def test_pad(self):
height = random.randint(10, 32) * 2
width = random.randint(10, 32) * 2
......
......@@ -532,6 +532,12 @@ class RandomCrop(torch.nn.Module):
"""
w, h = F._get_image_size(img)
th, tw = output_size
if h + 1 < th or w + 1 < 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
......
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