Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fix `RandomGaussianBlur` for sigma as tensor (#2220)

Julien Denize2783d9f641d0
diff --git a/kornia/augmentation/random_generator/_2d/gaussian_blur.py b/kornia/augmentation/random_generator/_2d/gaussian_blur.py
index b5fcfa80a..6c179f24d 100644
--- a/kornia/augmentation/random_generator/_2d/gaussian_blur.py
+++ b/kornia/augmentation/random_generator/_2d/gaussian_blur.py
@@ -42,7 +42,7 @@ class RandomGaussianBlurGenerator(RandomGeneratorBase):
if not isinstance(self.sigma, (torch.Tensor)):
sigma = torch.tensor(self.sigma, device=device, dtype=dtype)
else:
- sigma = sigma.to(device=device, dtype=dtype)
+ sigma = self.sigma.to(device=device, dtype=dtype)
_joint_range_check(sigma, "sigma", (0, float('inf')))
diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.py
index 9c2a0c4a0..5cbfc8236 100644
--- a/test/augmentation/test_augmentation.py
+++ b/test/augmentation/test_augmentation.py
@@ -3398,6 +3398,24 @@ class TestRandomGaussianBlur(BaseTester):
img = torch.ones(1, 3, 5, 5, device=device, dtype=dtype)
self.assert_close(op(img, *func_params), op_module(img))
+ def test_module_kernel_int(self, device, dtype):
+ func_params = [3, torch.tensor([1.5, 1.5]).view(1, -1)]
+ params = [3, (1.5, 1.5)]
+ op = kornia.filters.gaussian_blur2d
+ op_module = RandomGaussianBlur(*params)
+
+ img = torch.ones(1, 3, 5, 5, device=device, dtype=dtype)
+ self.assert_close(op(img, *func_params), op_module(img))
+
+ def test_module_sigma_tensor(self, device, dtype):
+ func_params = [(3, 3), torch.tensor([1.5, 1.5]).view(1, -1)]
+ params = [(3, 3), torch.tensor((1.5, 1.5))]
+ op = kornia.filters.gaussian_blur2d
+ op_module = RandomGaussianBlur(*params)
+
+ img = torch.ones(1, 3, 5, 5, device=device, dtype=dtype)
+ self.assert_close(op(img, *func_params), op_module(img))
+
@pytest.mark.skip(reason="not implemented yet")
def test_exception(self, device, dtype):
pass