Unverified Commit 71073cb5 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

add sequence fill support for ElasticTransform (#7141)

parent 2bc8a14d
...@@ -858,3 +858,35 @@ def test_gaussian_blur(device, channels, meth_kwargs): ...@@ -858,3 +858,35 @@ def test_gaussian_blur(device, channels, meth_kwargs):
agg_method="max", agg_method="max",
tol=tol, 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,
)
...@@ -1539,8 +1539,6 @@ def elastic_transform( ...@@ -1539,8 +1539,6 @@ def elastic_transform(
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0. 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. 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. 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(): if not torch.jit.is_scripting() and not torch.jit.is_tracing():
_log_api_usage_once(elastic_transform) _log_api_usage_once(elastic_transform)
......
...@@ -2104,8 +2104,12 @@ class ElasticTransform(torch.nn.Module): ...@@ -2104,8 +2104,12 @@ class ElasticTransform(torch.nn.Module):
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
self.interpolation = interpolation self.interpolation = interpolation
if not isinstance(fill, (int, float)): if isinstance(fill, (int, float)):
raise TypeError(f"fill should be int or float. Got {type(fill)}") 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 self.fill = fill
@staticmethod @staticmethod
......
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