Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fix RandomElasticTransform ignores same_on_batch (#1189)

bkntr778ca387a3e7
diff --git a/docs/source/_extra/googlef1b16a85a18694bd.html b/docs/source/_extra/googlef1b16a85a18694bd.html
index 3fd620691..8b7d1d6ed 100644
--- a/docs/source/_extra/googlef1b16a85a18694bd.html
+++ b/docs/source/_extra/googlef1b16a85a18694bd.html
@@ -1 +1 @@
-google-site-verification: googlef1b16a85a18694bd.html
\ No newline at end of file
+google-site-verification: googlef1b16a85a18694bd.html
diff --git a/docs/source/conf.py b/docs/source/conf.py
index dadf6f72d..b6d6cc084 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -124,7 +124,7 @@ html_theme_options = {
'analytics_id': 'G-3LJY4GJLPR',
'collapse_navigation': False,
'display_version': True,
- 'logo_only': True
+ 'logo_only': True,
}
html_logo = '_static/img/kornia_logo.svg'
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.py
index 5ceca0f28..a6f9ba81f 100644
--- a/kornia/augmentation/augmentation.py
+++ b/kornia/augmentation/augmentation.py
@@ -2159,7 +2159,11 @@ class RandomElasticTransform(GeometricAugmentationBase2D):
def generate_parameters(self, shape: torch.Size) -> Dict[str, torch.Tensor]:
B, _, H, W = shape
- return dict(noise=torch.rand(B, 2, H, W) * 2 - 1)
+ if self.same_on_batch:
+ noise = torch.rand(1, 2, H, W, device=self.device, dtype=self.dtype).repeat(B, 1, 1, 1)
+ else:
+ noise = torch.rand(B, 2, H, W, device=self.device, dtype=self.dtype)
+ return dict(noise=noise * 2 - 1)
def compute_transformation(self, input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:
return self.identity_matrix(input)
diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.py
index 0e413b05a..a51215be6 100644
--- a/test/augmentation/test_augmentation.py
+++ b/test/augmentation/test_augmentation.py
@@ -2763,6 +2763,12 @@ class TestRandomElasticTransform:
aug = RandomElasticTransform(p=1.0)
assert img.shape == aug(img).shape
+ def test_same_on_batch(self, device, dtype):
+ f = RandomElasticTransform(p=1.0, same_on_batch=True)
+ input = torch.eye(3, device=device, dtype=dtype).unsqueeze(dim=0).unsqueeze(dim=0).repeat(2, 1, 1, 1)
+ res = f(input)
+ assert (res[0] == res[1]).all()
+
class TestRandomThinPlateSpline:
def test_smoke(self, device, dtype):