Resize¶
- class torchvision.transforms.Resize(size, interpolation=InterpolationMode.BILINEAR, max_size=None, antialias=None)[source]¶
Resize the input image to the given size. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions
Warning
The output image might be different depending on its type: when downsampling, the interpolation of PIL images and tensors is slightly different, because PIL applies antialiasing. This may lead to significant differences in the performance of a network. Therefore, it is preferable to train and serve a model with the same input types. See also below the
antialiasparameter, which can help making the output of PIL images and tensors closer.- Parameters:
size (sequence or int) –
Desired output size. If size is a sequence like (h, w), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size).
Note
In torchscript mode size as single int is not supported, use a sequence of length 1:
[size, ].interpolation (InterpolationMode) – Desired interpolation enum defined by
torchvision.transforms.InterpolationMode. Default isInterpolationMode.BILINEAR. If input is Tensor, onlyInterpolationMode.NEAREST,InterpolationMode.BILINEARandInterpolationMode.BICUBICare supported. For backward compatibility integer values (e.g.PIL.Image[.Resampling].NEAREST) are still accepted, but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.max_size (int, optional) – The maximum allowed for the longer edge of the resized image: if the longer edge of the image is greater than
max_sizeafter being resized according tosize, then the image is resized again so that the longer edge is equal tomax_size. As a result,sizemight be overruled, i.e the smaller edge may be shorter thansize. This is only supported ifsizeis an int (or a sequence of length 1 in torchscript mode).antialias (bool, optional) – antialias flag. If
imgis PIL Image, the flag is ignored and anti-alias is always used. Ifimgis Tensor, the flag is False by default and can be set to True forInterpolationMode.BILINEARandInterpolationMode.BICUBICmodes. This can help making the output for PIL images and tensors closer.
Examples using
Resize: