From 00237438257d1a7657478bdfea9d2daaa9acfd0d Mon Sep 17 00:00:00 2001 From: ag14774 Date: Wed, 29 Jul 2020 16:19:06 +0200 Subject: [PATCH 1/2] Fixed resize to only match the smaller edge when an int is given instead of always --- torchvision/transforms/functional_tensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torchvision/transforms/functional_tensor.py b/torchvision/transforms/functional_tensor.py index f2e47b056d3..357f23b88fc 100644 --- a/torchvision/transforms/functional_tensor.py +++ b/torchvision/transforms/functional_tensor.py @@ -586,8 +586,8 @@ def resize(img: Tensor, size: List[int], interpolation: int = 2) -> Tensor: else: size_w = int(size_h * w / h) - if (w <= h and w == size_w) or (h <= w and h == size_h): - return img + if (w <= h and w == size_w) or (h <= w and h == size_h): + return img # make image NCHW need_squeeze = False From aaa6f68694a6b28d1fcaf0572ee84482ccf72f01 Mon Sep 17 00:00:00 2001 From: ag14774 Date: Thu, 30 Jul 2020 09:46:14 +0200 Subject: [PATCH 2/2] Added test cases for resize() --- test/test_functional_tensor.py | 2 +- test/test_transforms_tensor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_functional_tensor.py b/test/test_functional_tensor.py index 2e3477ad12b..d01a357d7b5 100644 --- a/test/test_functional_tensor.py +++ b/test/test_functional_tensor.py @@ -337,7 +337,7 @@ def test_resize(self): if dt is not None: # This is a trivial cast to float of uint8 data to test all cases tensor = tensor.to(dt) - for size in [32, [32, ], [32, 32], (32, 32), ]: + for size in [32, 26, [32, ], [32, 32], (32, 32), [26, 35]]: for interpolation in [BILINEAR, BICUBIC, NEAREST]: resized_tensor = F_t.resize(tensor, size=size, interpolation=interpolation) resized_pil_img = F_pil.resize(pil_img, size=size, interpolation=interpolation) diff --git a/test/test_transforms_tensor.py b/test/test_transforms_tensor.py index e05044599ef..e2085b0aaab 100644 --- a/test/test_transforms_tensor.py +++ b/test/test_transforms_tensor.py @@ -226,7 +226,7 @@ def test_resize(self): if dt is not None: # This is a trivial cast to float of uint8 data to test all cases tensor = tensor.to(dt) - for size in [32, [32, ], [32, 32], (32, 32), ]: + for size in [32, 34, [32, ], [32, 32], (32, 32), [34, 35]]: for interpolation in [BILINEAR, BICUBIC, NEAREST]: resized_tensor = F.resize(tensor, size=size, interpolation=interpolation) @@ -250,7 +250,7 @@ def test_resized_crop(self): for scale in [(0.7, 1.2), [0.7, 1.2]]: for ratio in [(0.75, 1.333), [0.75, 1.333]]: - for size in [(32, ), [32, ], [32, 32], (32, 32)]: + for size in [(32, ), [44, ], [32, ], [32, 32], (32, 32), [44, 55]]: for interpolation in [NEAREST, BILINEAR, BICUBIC]: transform = T.RandomResizedCrop( size=size, scale=scale, ratio=ratio, interpolation=interpolation