Skip to content

Commit

Permalink
Fixed resize to only match the smaller edge when an int is given (pyt…
Browse files Browse the repository at this point in the history
…orch#2518)

* Fixed resize to only match the smaller edge when an int is given instead of always

* Added test cases for resize()
  • Loading branch information
ag14774 authored and bryant1410 committed Nov 22, 2020
1 parent fe3e86d commit 97e6be9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/test_functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_transforms_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions torchvision/transforms/functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 97e6be9

Please sign in to comment.