π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
[fix] AugmentationSequential bbox keypoints transformation fix (#1570)
Jian Shiec4780f312d0
diff --git a/kornia/augmentation/container/utils.py b/kornia/augmentation/container/utils.pyindex af4ba33ab..4670f0158 100644--- a/kornia/augmentation/container/utils.py+++ b/kornia/augmentation/container/utils.py@@ -79,8 +79,12 @@ class ApplyInverseImpl(ApplyInverseInterface):to apply transformations.param: the corresponding parameters to the module."""-- mat: Optional[torch.Tensor] = cls._get_transformation(input, module, param)+ mat: Optional[torch.Tensor]+ if hasattr(module, "_transform_matrix") and module._transform_matrix is not None:+ mat = cast(torch.Tensor, module._transform_matrix)+ else:+ mat = cls._get_transformation(input, module, param)+ mat = torch.as_tensor(mat, device=input.device, dtype=input.dtype)to_apply = Noneif isinstance(module, _AugmentationBase):to_apply = param.data['batch_prob'] # type: ignore@@ -103,7 +107,12 @@ class ApplyInverseImpl(ApplyInverseInterface):to apply transformations.param: the corresponding parameters to the module."""- mat: Optional[torch.Tensor] = cls._get_transformation(input, module, param)+ mat: Optional[torch.Tensor]+ if hasattr(module, "_transform_matrix") and module._transform_matrix is not None:+ mat = cast(torch.Tensor, module._transform_matrix)+ else:+ mat = cls._get_transformation(input, module, param)+ mat = torch.as_tensor(mat, device=input.device, dtype=input.dtype)if mat is not None:transform: torch.Tensor = cls._get_inverse_transformation(mat)diff --git a/test/augmentation/test_container.py b/test/augmentation/test_container.pyindex d82d7cbb0..a7fb7b577 100644--- a/test/augmentation/test_container.py+++ b/test/augmentation/test_container.py@@ -363,6 +363,7 @@ class TestAugmentationSequential:assert torch.all(out[1][out[0] == fill_value] == 0.)def test_random_crops(self, device, dtype):+ torch.manual_seed(233)input = torch.randn(3, 3, 3, 3, device=device, dtype=dtype)bbox = torch.tensor([[[1.0, 1.0, 2.0, 2.0], [0.0, 0.0, 1.0, 2.0], [0.0, 0.0, 2.0, 1.0]]], device=device, dtype=dtype@@ -370,6 +371,7 @@ class TestAugmentationSequential:points = torch.tensor([[[0.0, 0.0], [1.0, 1.0]]], device=device, dtype=dtype).expand(3, -1, -1)aug = K.AugmentationSequential(K.RandomCrop((3, 3), padding=1, cropping_mode='resample', fill=0),+ K.RandomAffine((360., 360.), p=1.),data_keys=["input", "mask", "bbox_xyxy", "keypoints"],)