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
71073cb5
Unverified
Commit
71073cb5
authored
Jan 27, 2023
by
Philip Meier
Committed by
GitHub
Jan 27, 2023
Browse files
add sequence fill support for ElasticTransform (#7141)
parent
2bc8a14d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
4 deletions
+38
-4
test/test_transforms_tensor.py
test/test_transforms_tensor.py
+32
-0
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+0
-2
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+6
-2
No files found.
test/test_transforms_tensor.py
View file @
71073cb5
...
...
@@ -858,3 +858,35 @@ def test_gaussian_blur(device, channels, meth_kwargs):
agg_method
=
"max"
,
tol
=
tol
,
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_gpu
())
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
1
,
1.0
,
[
1
],
[
1.0
],
(
1
,),
(
1.0
,),
[
1
,
2
,
3
],
[
1.0
,
2.0
,
3.0
],
(
1
,
2
,
3
),
(
1.0
,
2.0
,
3.0
),
],
)
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
def
test_elastic_transform
(
device
,
channels
,
fill
):
if
isinstance
(
fill
,
(
list
,
tuple
))
and
len
(
fill
)
>
1
and
channels
==
1
:
# For this the test would correctly fail, since the number of channels in the image does not match `fill`.
# Thus, this is not an issue in the transform, but rather a problem of parametrization that just gives the
# product of `fill` and `channels`.
return
_test_class_op
(
T
.
ElasticTransform
,
meth_kwargs
=
dict
(
fill
=
fill
),
channels
=
channels
,
device
=
device
,
)
torchvision/transforms/functional.py
View file @
71073cb5
...
...
@@ -1539,8 +1539,6 @@ def elastic_transform(
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0.
If a tuple of length 3, it is used to fill R, G, B channels respectively.
This value is only used when the padding_mode is constant.
Only number is supported for torch Tensor.
Only int or str or tuple value is supported for PIL Image.
"""
if
not
torch
.
jit
.
is_scripting
()
and
not
torch
.
jit
.
is_tracing
():
_log_api_usage_once
(
elastic_transform
)
...
...
torchvision/transforms/transforms.py
View file @
71073cb5
...
...
@@ -2104,8 +2104,12 @@ class ElasticTransform(torch.nn.Module):
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
self
.
interpolation
=
interpolation
if
not
isinstance
(
fill
,
(
int
,
float
)):
raise
TypeError
(
f
"fill should be int or float. Got
{
type
(
fill
)
}
"
)
if
isinstance
(
fill
,
(
int
,
float
)):
fill
=
[
float
(
fill
)]
elif
isinstance
(
fill
,
(
list
,
tuple
)):
fill
=
[
float
(
f
)
for
f
in
fill
]
else
:
raise
TypeError
(
f
"fill should be int or float or a list or tuple of them. Got
{
type
(
fill
)
}
"
)
self
.
fill
=
fill
@
staticmethod
...
...
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