Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Mix up #1549

Merged
merged 23 commits into from
Mar 3, 2024
Merged

[WIP] Mix up #1549

merged 23 commits into from
Mar 3, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Feb 29, 2024

No description provided.

@ternaus ternaus changed the title Mix up [WIP] Mix up Feb 29, 2024
@ternaus ternaus requested a review from Dipet February 29, 2024 02:19
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Type: Enhancement

PR Summary: This pull request introduces the MixUp data augmentation technique across various augmentation classes and tests. It extends the functionality of the DualTransform class to support operations on images, masks, bounding boxes, keypoints, and class labels, ensuring consistency between an image and its annotations. The PR also includes updates to utility functions for reading images and introduces a new method for generating mixed arrays. Additionally, it incorporates the MixUp augmentation into the testing suite, ensuring its compatibility and effectiveness across different data types and augmentation scenarios.

Decision: Comment

📝 Type: 'Enhancement' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
📝 Complexity: the changes are too large or complex for Sourcery to approve.
  • Big diff: the diff is too large to approve with confidence.

General suggestions:

  • Consider adding more detailed documentation or examples on how to use the MixUp augmentation in different contexts, such as with or without masks and class labels.
  • It might be beneficial to include performance benchmarks or comparisons to demonstrate the impact of the MixUp augmentation on model training and generalization.
  • Ensure that the MixUp augmentation's parameters (e.g., alpha for the Beta distribution) are easily configurable to allow users to experiment with different mixing intensities.
albumentations/core/transforms_interface.py: Consider simplifying the class by abstracting common patterns into generic methods to reduce complexity and enhance maintainability.

While the added documentation and new methods enhance the functionality of the DualTransform class, they also introduce a significant amount of complexity. The extensive docstrings, although informative, could potentially obscure the core functionality and usage of the class. Additionally, the introduction of specific methods for class labels alongside existing methods for other data types increases the class's responsibilities, making it more challenging to maintain.

To simplify, consider abstracting the common pattern of applying transformations across different data types into more generic methods. This approach could reduce redundancy and make the class easier to extend in the future. For instance, a single method that handles the application of transformations to both individual items and sequences of items could streamline the code significantly.

Here's a suggested refactor that demonstrates this idea:

class DualTransform(BasicTransform):
    """
    Base class for dual transformations (image and annotations).
    """

    def __init__(self):
        self.targets = {
            "image": self.apply,
            "mask": self.apply_to_mask,
            "masks": self.apply_to_masks,
            "bboxes": self.apply_to_bboxes,
            "keypoints": self.apply_to_keypoints,
            "class_labels": self.apply_to_class_labels,
        }

    def apply_to_data(self, data, apply_func, **params):
        if isinstance(data, Sequence):
            return [apply_func(item, **params) for item in data]
        return apply_func(data, **params)

    def apply_to_class_labels(self, labels, **params):
        return self.apply_to_data(labels, self.apply_to_class_label, **params)

    # Example of a simplified method that uses apply_to_data
    def apply_to_masks(self, masks, **params):
        return self.apply_to_data(masks, self.apply_to_mask, **params)

    # Other methods remain similar but utilize apply_to_data where possible

This refactor aims to maintain the functionality while reducing complexity, making the codebase more maintainable and easier to understand.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

ternaus and others added 3 commits February 28, 2024 18:33
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@ternaus ternaus requested a review from Dipet March 1, 2024 04:11
@ternaus ternaus dismissed Dipet’s stale review March 3, 2024 23:52

Fixes are made, but I cannot merge.

@ternaus ternaus merged commit 138bc5c into main Mar 3, 2024
17 checks passed
@ternaus ternaus deleted the MixUp branch March 3, 2024 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants