Skip to content

Commit 591c899

Browse files
authored
Add warning in docs of Resize about different results for PIL and tensors (#3615)
* docs for resize * address comment: describe antialiasing
1 parent 7d955df commit 591c899

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

torchvision/transforms/functional.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationMode = Inte
346346
If the image is torch Tensor, it is expected
347347
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
348348
349+
.. warning::
350+
The output image might be different depending on its type: when downsampling, the interpolation of PIL images
351+
and tensors is slightly different, because PIL applies antialiasing. This may lead to significant differences
352+
in the performance of a network. Therefore, it is preferable to train and serve a model with the same input
353+
types.
354+
349355
Args:
350356
img (PIL Image or Tensor): Image to be resized.
351357
size (sequence or int): Desired output size. If size is a sequence like

torchvision/transforms/transforms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ class Resize(torch.nn.Module):
229229
If the image is torch Tensor, it is expected
230230
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
231231
232+
.. warning::
233+
The output image might be different depending on its type: when downsampling, the interpolation of PIL images
234+
and tensors is slightly different, because PIL applies antialiasing. This may lead to significant differences
235+
in the performance of a network. Therefore, it is preferable to train and serve a model with the same input
236+
types.
237+
232238
Args:
233239
size (sequence or int): Desired output size. If size is a sequence like
234240
(h, w), output size will be matched to this. If size is an int,

0 commit comments

Comments
 (0)