Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix(augmentation): raise the documented error from a mix inverse(output) (#6033)

Saksham Sharma47ba1ae176ad
diff --git a/changelog.d/6033.fixed.md b/changelog.d/6033.fixed.md
new file mode 100644
index 000000000..2a1766681
--- /dev/null
+++ b/changelog.d/6033.fixed.md
@@ -0,0 +1 @@
+The mix augmentations (`RandomMixUpV2`, `RandomCutMixV2`, `RandomMosaic`, `RandomJigsaw`, `PatchMix`, `RandomTransplantation` and `RandomTransplantation3D`) raise the documented `RuntimeError: Inverse for <Class> is not supported.` from `inverse(output)` and `inverse(output, params=...)`. Previously only a call without positional arguments did; these call forms raised `TypeError: MixAugmentationBaseV2.inverse() takes 1 positional argument but 2 were given`.
diff --git a/kornia/augmentation/_2d/mix/base.py b/kornia/augmentation/_2d/mix/base.py
index e5ef8909b..8c0f672d9 100644
--- a/kornia/augmentation/_2d/mix/base.py
+++ b/kornia/augmentation/_2d/mix/base.py
@@ -322,7 +322,9 @@ class MixAugmentationBaseV2(_BasicAugmentationBase):
return outputs
@torch.jit.ignore
- def inverse(self, **kwargs: Any) -> Optional[torch.Tensor]:
+ def inverse(self, *args: Any, **kwargs: Any) -> Optional[torch.Tensor]:
+ # Accept the usual ``inverse(output, params=...)`` call too, so every call form raises this error rather
+ # than a signature TypeError.
raise RuntimeError(f"Inverse for {self.__class__.__name__} is not supported.")
@property
diff --git a/tests/augmentation/test_conventions_mix.py b/tests/augmentation/test_conventions_mix.py
index 1bb655d7b..f709835c8 100644
--- a/tests/augmentation/test_conventions_mix.py
+++ b/tests/augmentation/test_conventions_mix.py
@@ -54,6 +54,14 @@ class TestMixConventions(BaseTester):
_ = aug.transform_matrix
with pytest.raises(RuntimeError, match="Inverse"):
aug.inverse()
+ # The usual call forms used to raise a signature TypeError instead (#6031).
+ output = torch.zeros(1)
+ with pytest.raises(RuntimeError, match=f"Inverse for {type(aug).__name__} is not supported"):
+ aug.inverse(output)
+ with pytest.raises(RuntimeError, match=f"Inverse for {type(aug).__name__} is not supported"):
+ aug.inverse(output, params={})
+ with pytest.raises(RuntimeError, match=f"Inverse for {type(aug).__name__} is not supported"):
+ aug.inverse(output, {}, extra_args={})
@pytest.mark.parametrize(
("factory", "shape"),