π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
docs(augmentation): RandomElasticTransform's alpha is (x, y) (#4510)
Dipak Chaudhari8f9ad5e3ecac
diff --git a/changelog.d/4510.fixed.md b/changelog.d/4510.fixed.mdnew file mode 100644index 000000000..665da5f20--- /dev/null+++ b/changelog.d/4510.fixed.md@@ -0,0 +1,2 @@+`RandomElasticTransform` documents `alpha` in the order the code applies it, `(x, y)`; it said `(y, x)`, the order+`kernel_size` and `sigma` use, so an anisotropic `alpha` warped the other axis from the one documented. (#4418)diff --git a/kornia/augmentation/_2d/geometric/elastic_transform.py b/kornia/augmentation/_2d/geometric/elastic_transform.pyindex 49ac10c49..5610619e6 100644--- a/kornia/augmentation/_2d/geometric/elastic_transform.py+++ b/kornia/augmentation/_2d/geometric/elastic_transform.py@@ -31,11 +31,11 @@ class RandomElasticTransform(AugmentationBase2D):.. image:: _static/img/RandomElasticTransform.pngArgs:- kernel_size: the size of the Gaussian kernel.+ kernel_size: the size of the Gaussian kernel, in the y and x directions, respectively.sigma: The standard deviation of the Gaussian in the y and x directions,respectively. Larger sigma results in smaller pixel displacements.alpha: The scaling factor that controls the intensity of the deformation- in the y and x directions, respectively.+ in the x and y directions, respectively -- the opposite order to ``kernel_size`` and ``sigma``.align_corners: Interpolation flag used by `grid_sample`.resample: Interpolation mode used by `grid_sample`. Either 'nearest' (0) or 'bilinear' (1).padding_mode: The padding used by ```grid_sample```. Either 'torch.zeros', 'border' or 'refection'.diff --git a/tests/augmentation/test_augmentation.py b/tests/augmentation/test_augmentation.pyindex c42e34e84..da975eec3 100644--- a/tests/augmentation/test_augmentation.py+++ b/tests/augmentation/test_augmentation.py@@ -4814,6 +4814,23 @@ class TestRandomElasticTransform(BaseTester):aug = RandomElasticTransform(p=1.0)assert img.shape == aug(img).shape+ def test_alpha_is_x_then_y(self, device, dtype):+ # #4418: `alpha` is (x, y), unlike `kernel_size` and `sigma`, which are (y, x). The image is constant+ # down each column, so a vertical displacement cannot change it and a horizontal one must.+ img = torch.arange(8, device=device, dtype=dtype).repeat(6, 1).reshape(1, 1, 6, 8)+ noise = torch.ones(1, 2, 6, 8, device=device, dtype=dtype)+ params = {"noise": noise, "batch_prob": torch.tensor([True], device=device)}++ def warp(alpha):+ aug = RandomElasticTransform(+ kernel_size=(3, 3), sigma=(1.0, 1.0), alpha=alpha, padding_mode="border", p=1.0+ )+ return aug(img, params=params)++ still = warp((0.0, 0.0))+ self.assert_close(warp((0.0, 4.0)), still)+ assert (warp((4.0, 0.0)) - still).abs().max().item() > 1.0+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)