From d9e24fa9bd76a256484e63533479570bd0c4d470 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 29 Oct 2024 09:16:51 +0000 Subject: [PATCH 1/3] fix OneOf and AugmentationsSequence to process bboxes properly --- augraphy/base/augmentationpipeline.py | 5 ++++- augraphy/base/augmentationsequence.py | 2 +- augraphy/base/oneof.py | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/augraphy/base/augmentationpipeline.py b/augraphy/base/augmentationpipeline.py index 0c85864..73e01ba 100644 --- a/augraphy/base/augmentationpipeline.py +++ b/augraphy/base/augmentationpipeline.py @@ -11,6 +11,7 @@ from augraphy.base.augmentation import Augmentation from augraphy.base.augmentationresult import AugmentationResult from augraphy.base.augmentationsequence import AugmentationSequence +from augraphy.base.oneof import OneOf from augraphy.utilities.detectdpi import dpi_resize from augraphy.utilities.detectdpi import DPIMetrics from augraphy.utilities.overlaybuilder import OverlayBuilder @@ -750,7 +751,9 @@ def apply_phase(self, data, layer, phase): data["log"]["time"].append((augmentation, elapsed)) # not "OneOf" or "AugmentationSequence" - if isinstance(augmentation, Augmentation): + if isinstance(augmentation, Augmentation) \ + and not isinstance(augmentation, AugmentationSequence) \ + and not isinstance(augmentation, OneOf): # unpacking augmented image, mask, keypoints and bounding boxes from output if (mask is not None) or (keypoints is not None) or (bounding_boxes is not None): result, mask, keypoints, bounding_boxes = result diff --git a/augraphy/base/augmentationsequence.py b/augraphy/base/augmentationsequence.py index 66f306e..8f475df 100644 --- a/augraphy/base/augmentationsequence.py +++ b/augraphy/base/augmentationsequence.py @@ -48,5 +48,5 @@ def __call__(self, image, layer=None, mask=None, keypoints=None, bounding_boxes= elif isinstance(current_result, tuple): if current_result[0] is not None: result = current_result - + result = (result, mask, keypoints, bounding_boxes) return result, self.augmentations diff --git a/augraphy/base/oneof.py b/augraphy/base/oneof.py index 74949af..94d4a82 100644 --- a/augraphy/base/oneof.py +++ b/augraphy/base/oneof.py @@ -29,8 +29,10 @@ def __call__(self, image, layer=None, mask=None, keypoints=None, bounding_boxes= augmentation = self.augmentations[np.argmax(self.augmentation_probabilities)] # Applies the selected Augmentation. - image = augmentation(image, mask=mask, keypoints=keypoints, bounding_boxes=bounding_boxes, force=True) - return image, [augmentation] + result = augmentation(image, mask=mask, keypoints=keypoints, bounding_boxes=bounding_boxes, force=True) + if isinstance(augmentation, AugmentationSequence): + return result[0], result[1] + return result, [augmentation] # Constructs a string containing the representations # of each augmentation From c95b7eb4f51e2a41db6972fe39bd312d43943f7b Mon Sep 17 00:00:00 2001 From: Ahmed Dusuki Date: Sat, 1 Feb 2025 17:46:02 +0200 Subject: [PATCH 2/3] Fixed augmentationsequence returning incorrect result shape. Caused an error when unpacking result tuple in augmentationpipeline's apply_phase. --- augraphy/base/augmentationsequence.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/augraphy/base/augmentationsequence.py b/augraphy/base/augmentationsequence.py index 8f475df..557ce1b 100644 --- a/augraphy/base/augmentationsequence.py +++ b/augraphy/base/augmentationsequence.py @@ -48,5 +48,6 @@ def __call__(self, image, layer=None, mask=None, keypoints=None, bounding_boxes= elif isinstance(current_result, tuple): if current_result[0] is not None: result = current_result - result = (result, mask, keypoints, bounding_boxes) + if (mask is not None) or (keypoints is not None) or (bounding_boxes is not None): + result = (result, mask, keypoints, bounding_boxes) return result, self.augmentations From 6e055742850405876b7ebbce12b568fe14bd26c3 Mon Sep 17 00:00:00 2001 From: Ahmed Dusuki Date: Sat, 15 Feb 2025 03:54:55 +0200 Subject: [PATCH 3/3] Apply formatting changes from pre-commit hooks. --- augraphy/base/augmentationpipeline.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/augraphy/base/augmentationpipeline.py b/augraphy/base/augmentationpipeline.py index 73e01ba..d465828 100644 --- a/augraphy/base/augmentationpipeline.py +++ b/augraphy/base/augmentationpipeline.py @@ -751,9 +751,11 @@ def apply_phase(self, data, layer, phase): data["log"]["time"].append((augmentation, elapsed)) # not "OneOf" or "AugmentationSequence" - if isinstance(augmentation, Augmentation) \ - and not isinstance(augmentation, AugmentationSequence) \ - and not isinstance(augmentation, OneOf): + if ( + isinstance(augmentation, Augmentation) + and not isinstance(augmentation, AugmentationSequence) + and not isinstance(augmentation, OneOf) + ): # unpacking augmented image, mask, keypoints and bounding boxes from output if (mask is not None) or (keypoints is not None) or (bounding_boxes is not None): result, mask, keypoints, bounding_boxes = result