π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Zca inverse transform fix (#695)
Diego4093882f3c5a
diff --git a/kornia/enhance/zca.py b/kornia/enhance/zca.pyindex d287c172d..d0675823c 100644--- a/kornia/enhance/zca.py+++ b/kornia/enhance/zca.py@@ -260,7 +260,7 @@ def zca_mean(inp: torch.Tensor, dim: int = 0,T_inv: Optional[torch.Tensor] = Noneif return_inverse:- T_inv = (U).mm(torch.sqrt(S) * U.t())+ T_inv = (U).mm(torch.sqrt(S + eps) * U.t())return T, mean, T_invdiff --git a/test/enhance/test_zca.py b/test/enhance/test_zca.pyindex d3ad59804..86e0e1015 100644--- a/test/enhance/test_zca.py+++ b/test/enhance/test_zca.py@@ -58,8 +58,8 @@ class TestZCA:assert_allclose(actual, expected)- @pytest.mark.parametrize("input_shape", [(15, 2, 2, 2), (10, 4), (20, 3, 2, 2)])- def test_identity(self, input_shape, device):+ @pytest.mark.parametrize("input_shape,eps", [((15, 2, 2, 2), 1e-6), ((10, 4), .1), ((20, 3, 2, 2), 1e-3)])+ def test_identity(self, input_shape, eps, device):"""Assert that data can be recovered by the inverse transform@@ -68,7 +68,7 @@ class TestZCA:data = torch.randn(*input_shape, dtype=torch.float32).to(device)- zca = kornia.enhance.ZCAWhitening(compute_inv=True).fit(data)+ zca = kornia.enhance.ZCAWhitening(compute_inv=True, eps=eps).fit(data)data_w = zca(data)