Unverified Commit b8de0b84 authored by vfdev's avatar vfdev Committed by GitHub
Browse files

Recoded gaussian blur without using to_tensor (#5503)

parent 60449a44
...@@ -3,7 +3,7 @@ from typing import Optional, List ...@@ -3,7 +3,7 @@ from typing import Optional, List
import PIL.Image import PIL.Image
import torch import torch
from torchvision.transforms import functional_tensor as _FT from torchvision.transforms import functional_tensor as _FT
from torchvision.transforms.functional import to_tensor, to_pil_image from torchvision.transforms.functional import pil_to_tensor, to_pil_image
normalize_image_tensor = _FT.normalize normalize_image_tensor = _FT.normalize
...@@ -39,4 +39,6 @@ def gaussian_blur_image_tensor( ...@@ -39,4 +39,6 @@ def gaussian_blur_image_tensor(
def gaussian_blur_image_pil(img: PIL.Image, kernel_size: List[int], sigma: Optional[List[float]] = None) -> PIL.Image: def gaussian_blur_image_pil(img: PIL.Image, kernel_size: List[int], sigma: Optional[List[float]] = None) -> PIL.Image:
return to_pil_image(gaussian_blur_image_tensor(to_tensor(img), kernel_size=kernel_size, sigma=sigma)) t_img = pil_to_tensor(img)
output = gaussian_blur_image_tensor(t_img, kernel_size=kernel_size, sigma=sigma)
return to_pil_image(output, mode=img.mode)
...@@ -403,11 +403,8 @@ def resize( ...@@ -403,11 +403,8 @@ def resize(
mode). mode).
antialias (bool, optional): antialias flag. If ``img`` is PIL Image, the flag is ignored and anti-alias antialias (bool, optional): antialias flag. If ``img`` is PIL Image, the flag is ignored and anti-alias
is always used. If ``img`` is Tensor, the flag is False by default and can be set to True for is always used. If ``img`` is Tensor, the flag is False by default and can be set to True for
``InterpolationMode.BILINEAR`` only mode. This can help making the output for PIL images and tensors ``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` modes.
closer. This can help making the output for PIL images and tensors closer.
.. warning::
There is no autodiff support for ``antialias=True`` option with input ``img`` as Tensor.
Returns: Returns:
PIL Image or Tensor: Resized image. PIL Image or Tensor: Resized image.
...@@ -1338,12 +1335,12 @@ def gaussian_blur(img: Tensor, kernel_size: List[int], sigma: Optional[List[floa ...@@ -1338,12 +1335,12 @@ def gaussian_blur(img: Tensor, kernel_size: List[int], sigma: Optional[List[floa
if not F_pil._is_pil_image(img): if not F_pil._is_pil_image(img):
raise TypeError(f"img should be PIL Image or Tensor. Got {type(img)}") raise TypeError(f"img should be PIL Image or Tensor. Got {type(img)}")
t_img = to_tensor(img) t_img = pil_to_tensor(img)
output = F_t.gaussian_blur(t_img, kernel_size, sigma) output = F_t.gaussian_blur(t_img, kernel_size, sigma)
if not isinstance(img, torch.Tensor): if not isinstance(img, torch.Tensor):
output = to_pil_image(output) output = to_pil_image(output, mode=img.mode)
return output return output
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment