Skip to content

Commit d9265f0

Browse files
committed
Added warning about deprecated to_tensor/ToTensor
Additionally, fixed docs for resize/antialias option
1 parent 95d4189 commit d9265f0

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

torchvision/prototype/transforms/functional/_misc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import PIL.Image
44
import torch
55
from torchvision.transforms import functional_tensor as _FT
6-
from torchvision.transforms.functional import to_tensor, to_pil_image
6+
from torchvision.transforms.functional import pil_to_tensor, to_pil_image
77

88

99
normalize_image_tensor = _FT.normalize
@@ -39,4 +39,6 @@ def gaussian_blur_image_tensor(
3939

4040

4141
def gaussian_blur_image_pil(img: PIL.Image, kernel_size: List[int], sigma: Optional[List[float]] = None) -> PIL.Image:
42-
return to_pil_image(gaussian_blur_image_tensor(to_tensor(img), kernel_size=kernel_size, sigma=sigma))
42+
t_img = pil_to_tensor(img)
43+
output = gaussian_blur_image_tensor(t_img, kernel_size=kernel_size, sigma=sigma)
44+
return to_pil_image(output, mode=img.mode)

torchvision/transforms/functional.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def to_tensor(pic):
126126
127127
See :class:`~torchvision.transforms.ToTensor` for more details.
128128
129+
.. warning::
130+
This method is deprecated, please use :meth:`~torchvision.transforms.functional.pil_to_tensor`.
131+
129132
Args:
130133
pic (PIL Image or numpy.ndarray): Image to be converted to tensor.
131134
@@ -403,11 +406,8 @@ def resize(
403406
mode).
404407
antialias (bool, optional): antialias flag. If ``img`` is PIL Image, the flag is ignored and anti-alias
405408
is always used. If ``img`` is Tensor, the flag is False by default and can be set to True for
406-
``InterpolationMode.BILINEAR`` only mode. This can help making the output for PIL images and tensors
407-
closer.
408-
409-
.. warning::
410-
There is no autodiff support for ``antialias=True`` option with input ``img`` as Tensor.
409+
``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` modes.
410+
This can help making the output for PIL images and tensors closer.
411411
412412
Returns:
413413
PIL Image or Tensor: Resized image.

torchvision/transforms/transforms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class ToTensor:
114114
115115
In the other cases, tensors are returned without scaling.
116116
117+
.. warning::
118+
This method is deprecated, please use :meth:`~torchvision.transforms.functional.pil_to_tensor`.
119+
117120
.. note::
118121
Because the input image is scaled to [0.0, 1.0], this transformation should not be used when
119122
transforming target image masks. See the `references`_ for implementing the transforms for image masks.

0 commit comments

Comments
 (0)