Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
b8de0b84
Unverified
Commit
b8de0b84
authored
Mar 01, 2022
by
vfdev
Committed by
GitHub
Mar 01, 2022
Browse files
Recoded gaussian blur without using to_tensor (#5503)
parent
60449a44
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
9 deletions
+8
-9
torchvision/prototype/transforms/functional/_misc.py
torchvision/prototype/transforms/functional/_misc.py
+4
-2
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+4
-7
No files found.
torchvision/prototype/transforms/functional/_misc.py
View file @
b8de0b84
...
@@ -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
)
torchvision/transforms/functional.py
View file @
b8de0b84
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment