Skip to content

Commit df6a796

Browse files
authored
Fixed resize to only match the smaller edge when an int is given (#2518)
* Fixed resize to only match the smaller edge when an int is given instead of always * Added test cases for resize()
1 parent 3a159df commit df6a796

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

test/test_functional_tensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def test_resize(self):
337337
if dt is not None:
338338
# This is a trivial cast to float of uint8 data to test all cases
339339
tensor = tensor.to(dt)
340-
for size in [32, [32, ], [32, 32], (32, 32), ]:
340+
for size in [32, 26, [32, ], [32, 32], (32, 32), [26, 35]]:
341341
for interpolation in [BILINEAR, BICUBIC, NEAREST]:
342342
resized_tensor = F_t.resize(tensor, size=size, interpolation=interpolation)
343343
resized_pil_img = F_pil.resize(pil_img, size=size, interpolation=interpolation)

test/test_transforms_tensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_resize(self):
226226
if dt is not None:
227227
# This is a trivial cast to float of uint8 data to test all cases
228228
tensor = tensor.to(dt)
229-
for size in [32, [32, ], [32, 32], (32, 32), ]:
229+
for size in [32, 34, [32, ], [32, 32], (32, 32), [34, 35]]:
230230
for interpolation in [BILINEAR, BICUBIC, NEAREST]:
231231

232232
resized_tensor = F.resize(tensor, size=size, interpolation=interpolation)
@@ -250,7 +250,7 @@ def test_resized_crop(self):
250250

251251
for scale in [(0.7, 1.2), [0.7, 1.2]]:
252252
for ratio in [(0.75, 1.333), [0.75, 1.333]]:
253-
for size in [(32, ), [32, ], [32, 32], (32, 32)]:
253+
for size in [(32, ), [44, ], [32, ], [32, 32], (32, 32), [44, 55]]:
254254
for interpolation in [NEAREST, BILINEAR, BICUBIC]:
255255
transform = T.RandomResizedCrop(
256256
size=size, scale=scale, ratio=ratio, interpolation=interpolation

torchvision/transforms/functional_tensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ def resize(img: Tensor, size: List[int], interpolation: int = 2) -> Tensor:
586586
else:
587587
size_w = int(size_h * w / h)
588588

589-
if (w <= h and w == size_w) or (h <= w and h == size_h):
590-
return img
589+
if (w <= h and w == size_w) or (h <= w and h == size_h):
590+
return img
591591

592592
# make image NCHW
593593
need_squeeze = False

0 commit comments

Comments
 (0)