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

Added ConstrainedCoarseDropout class #2226

Conversation

vedantdalimkar
Copy link
Contributor

@vedantdalimkar vedantdalimkar commented Dec 31, 2024

Added a new transform - Constrained coarse droput, which is a modification of the coarse dropout transform.
In constrained coarse dropout, rectangular regions are only dropped out from the foreground objects belonging to the class specified by the user.

Summary by Sourcery

Introduce the ConstrainedCoarseDropout transform. This transform drops out rectangular regions within user-specified foreground object classes, enhancing the CoarseDropout functionality.

New Features:

  • Added a new transform called ConstrainedCoarseDropout. This transform allows for dropping out rectangular regions exclusively from foreground objects belonging to specific user-defined classes.

Tests:

  • Added unit tests for the ConstrainedCoarseDropout transform.

Copy link
Contributor

sourcery-ai bot commented Dec 31, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new transform called ConstrainedCoarseDropout, which is a modification of the existing CoarseDropout transform. The main difference is that ConstrainedCoarseDropout only drops out rectangular regions from foreground objects belonging to specific classes specified by the user. This allows for more targeted dropout, focusing on particular objects within an image.

Sequence diagram for ConstrainedCoarseDropout transform operation

sequenceDiagram
    participant T as Transform
    participant M as Mask
    participant CV as OpenCV
    participant H as Holes
    T->>M: Get mask for specified classes
    T->>CV: Find contours in mask
    CV-->>T: Return contours
    T->>CV: Get bounding boxes for contours
    CV-->>T: Return bounding boxes
    T->>H: Calculate hole dimensions
    T->>H: Calculate hole positions
    H-->>T: Return hole parameters
    T->>M: Apply dropout to image and mask
Loading

Class diagram showing the new ConstrainedCoarseDropout class hierarchy

classDiagram
    class BaseDropout {
        +_targets: tuple[Targets, ...] | Targets
        +fill: DropoutFillValue
        +fill_mask: ColorType
    }
    class CoarseDropout {
        +num_holes_range: tuple[int, int]
        +hole_height_range: tuple[float, float]
        +hole_width_range: tuple[float, float]
    }
    class ConstrainedCoarseDropout {
        +num_holes_range: tuple[int, int]
        +hole_height_range: tuple[float, float]
        +hole_width_range: tuple[float, float]
        +class_indices: list[int]
        +calculate_constrained_hole_dimensions()
        +get_hole_origin_coordinates()
        +get_bbox_coords()
        +get_foreground_objects_bounding_box_coords()
    }
    BaseDropout <|-- CoarseDropout
    CoarseDropout <|-- ConstrainedCoarseDropout
    note for ConstrainedCoarseDropout "New class that applies dropout only to specific object classes"
Loading

File-Level Changes

Change Details Files
Added the ConstrainedCoarseDropout class.
  • Implemented the ConstrainedCoarseDropout class, inheriting from CoarseDropout. This class allows for dropping out rectangular regions within specified foreground object classes.
  • Added parameters class_indices, num_holes_range, hole_height_range, and hole_width_range to control the dropout behavior.
  • Implemented methods to calculate hole dimensions and origin coordinates based on the bounding boxes of the specified foreground objects.
  • Added logic to handle cases where no mask is provided or no class indices are specified, defaulting to the behavior of CoarseDropout.
albumentations/augmentations/dropout/coarse_dropout.py
Added tests for the ConstrainedCoarseDropout class.
  • Included ConstrainedCoarseDropout in the test suite to ensure its functionality and compatibility with other augmentations.
  • Added tests to verify the behavior of ConstrainedCoarseDropout with different input types, including single-channel and multi-channel images.
  • Added tests to check the handling of cases where no mask is provided or no class indices are specified.
tests/aug_definitions.py
tests/test_augmentations.py
tests/test_core.py
Updated documentation and other files.
  • Updated the README to include ConstrainedCoarseDropout in the list of available transforms.
  • Modified the type annotations in transforms.py to accommodate the new transform and its parameters.
README.md
albumentations/augmentations/dropout/transforms.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

Hey @vedantdalimkar - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider moving the README documentation link updates to a separate PR since they're unrelated to the ConstrainedCoarseDropout feature
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

tests/test_augmentations.py Show resolved Hide resolved
tests/test_augmentations.py Show resolved Hide resolved
tests/test_core.py Show resolved Hide resolved
@vedantdalimkar
Copy link
Contributor Author

vedantdalimkar commented Jan 1, 2025

@ternaus I have added some code for the test case which was failing. Sorry for the hiccup. All test cases are passing now.

Are there any more issues to address with respect to the code?

@ternaus ternaus merged commit edb09e3 into albumentations-team:main Jan 1, 2025
14 checks passed
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