Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fix for nested AugmentationSequential containers (#1467)

Miquel Martí0a588ddb9f7c
diff --git a/kornia/augmentation/container/augment.py b/kornia/augmentation/container/augment.py
index d3c6fd975..8eb7625fe 100644
--- a/kornia/augmentation/container/augment.py
+++ b/kornia/augmentation/container/augment.py
@@ -286,7 +286,7 @@ class AugmentationSequential(ImageSequential):
input = cast(TensorWithTransformMat, out)
outputs[idx] = input
- self.return_label = label is not None or self.contains_label_operations(params)
+ self.return_label = self.return_label or label is not None or self.contains_label_operations(params)
for idx, (input, dcate, out) in enumerate(zip(args, data_keys, outputs)):
if out is not None:
diff --git a/kornia/augmentation/container/utils.py b/kornia/augmentation/container/utils.py
index 7206e5919..deeeb0a94 100644
--- a/kornia/augmentation/container/utils.py
+++ b/kornia/augmentation/container/utils.py
@@ -166,7 +166,7 @@ class InputApplyInverse(ApplyInverseImpl):
param: the corresponding parameters to the module.
"""
if isinstance(module, (MixAugmentationBase,)):
- input, label = module(input, label, params=param.data)
+ input, label = module(input, label=label, params=param.data)
elif isinstance(module, (_AugmentationBase,)):
input = module(input, params=param.data)
elif isinstance(module, kornia.augmentation.container.ImageSequential):
@@ -174,7 +174,7 @@ class InputApplyInverse(ApplyInverseImpl):
temp2 = module.return_label
module.apply_inverse_func = InputApplyInverse
module.return_label = True
- input, label = module(input, label, param.data)
+ input, label = module(input, label=label, params=param.data)
module.apply_inverse_func = temp
module.return_label = temp2
else:
@@ -198,11 +198,11 @@ class InputApplyInverse(ApplyInverseImpl):
param: the corresponding parameters to the module.
"""
if isinstance(module, GeometricAugmentationBase2D):
- input = module.inverse(input, None if param is None else cast(Dict, param.data))
+ input = module.inverse(input, params=None if param is None else cast(Dict, param.data))
elif isinstance(module, kornia.augmentation.container.ImageSequential):
temp = module.apply_inverse_func
module.apply_inverse_func = InputApplyInverse
- input = module.inverse(input, None if param is None else cast(List, param.data))
+ input = module.inverse(input, params=None if param is None else cast(List, param.data))
module.apply_inverse_func = temp
return input
@@ -244,13 +244,13 @@ class MaskApplyInverse(ApplyInverseImpl):
if isinstance(module, GeometricAugmentationBase2D):
_param = cast(Dict[str, torch.Tensor], _param)
- input = module(input, _param, return_transform=False)
+ input = module(input, params=_param, return_transform=False)
elif isinstance(module, kornia.augmentation.container.ImageSequential) and not module.is_intensity_only():
_param = cast(List[ParamItem], _param)
temp = module.apply_inverse_func
module.apply_inverse_func = MaskApplyInverse
geo_param: List[ParamItem] = _get_geometric_only_param(module, _param)
- input = cls.make_input_only_sequential(module)(input, None, geo_param)
+ input = cls.make_input_only_sequential(module)(input, label=None, params=geo_param)
module.apply_inverse_func = temp
else:
pass # No need to update anything
@@ -269,11 +269,11 @@ class MaskApplyInverse(ApplyInverseImpl):
param: the corresponding parameters to the module.
"""
if isinstance(module, GeometricAugmentationBase2D):
- input = module.inverse(input, None if param is None else cast(Dict, param.data))
+ input = module.inverse(input, params=None if param is None else cast(Dict, param.data))
elif isinstance(module, kornia.augmentation.container.ImageSequential):
temp = module.apply_inverse_func
module.apply_inverse_func = MaskApplyInverse
- input = module.inverse(input, None if param is None else cast(List, param.data))
+ input = module.inverse(input, params=None if param is None else cast(List, param.data))
module.apply_inverse_func = temp
return input
diff --git a/test/augmentation/test_container.py b/test/augmentation/test_container.py
index ad5d31ddf..95d8b424a 100644
--- a/test/augmentation/test_container.py
+++ b/test/augmentation/test_container.py
@@ -311,6 +311,9 @@ class TestAugmentationSequential:
K.ImageSequential(
K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
),
+ K.AugmentationSequential(
+ K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
+ ),
K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0),
K.RandomAffine(360, p=1.0),
data_keys=["input", "mask", "bbox", "keypoints"],
@@ -345,6 +348,9 @@ class TestAugmentationSequential:
K.ImageSequential(
K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
),
+ K.AugmentationSequential(
+ K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
+ ),
K.RandomAffine(360, p=1.0, return_transform=False),
data_keys=['input', 'mask', 'bbox', 'keypoints'],
)
@@ -373,6 +379,9 @@ class TestAugmentationSequential:
K.ImageSequential(
K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
),
+ K.AugmentationSequential(
+ K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
+ ),
K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0, return_transform=True),
K.RandomAffine(360, p=1.0, return_transform=True),
data_keys=["input", "mask", "bbox", "keypoints"],
@@ -404,6 +413,9 @@ class TestAugmentationSequential:
K.ImageSequential(
K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
),
+ K.AugmentationSequential(
+ K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0), K.RandomAffine(360, p=1.0, return_transform=True)
+ ),
K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0, return_transform=True),
K.RandomAffine(360, p=1.0, return_transform=True),
data_keys=["input", "mask", "bbox", "keypoints"],