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

Add random erasing #2136

Merged
merged 6 commits into from
Nov 12, 2024
Merged

Add random erasing #2136

merged 6 commits into from
Nov 12, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 12, 2024

Fixes: #2084

Summary by Sourcery

Add new 'Erasing' and 'RandomErasing' augmentation classes to support random erasing of image regions, enhancing model robustness. Update documentation and tests to reflect these additions.

New Features:

  • Introduce the 'Erasing' augmentation class, which implements the Random Erasing Data Augmentation technique to improve model robustness by randomly erasing rectangular regions in images.
  • Add 'RandomErasing' class as an alias for the 'Erasing' transform, providing compatibility with torchvision's API.

Documentation:

  • Update README.md to include documentation links for the new 'Erasing' and 'RandomErasing' transforms.

Tests:

  • Add tests for the new 'Erasing' and 'RandomErasing' transforms to ensure their correct functionality.

Copy link
Contributor

sourcery-ai bot commented Nov 12, 2024

Reviewer's Guide by Sourcery

This PR implements Random Erasing data augmentation by adding two new transforms: Erasing and its torchvision-compatible alias RandomErasing. The implementation includes mathematical optimizations for parameter calculation and supports various filling methods for erased regions.

Class diagram for the new Erasing and RandomErasing classes

classDiagram
    class BaseDropout {
        <<abstract>>
    }
    class Erasing {
        +tuple[float, float] scale
        +tuple[float, float] ratio
        +DropoutFillValue fill_value
        +ColorType mask_fill_value
        +float p
        +get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]
        +get_transform_init_args_names() tuple[str, ...]
    }
    class RandomErasing {
        +tuple[float, float] scale
        +tuple[float, float] ratio
        +float | tuple[float, ...] | Literal["random"] value
        +float p
        +get_transform_init_args_names() tuple[str, ...]
    }
    BaseDropout <|-- Erasing
    Erasing <|-- RandomErasing
    note for Erasing "Implements Random Erasing Data Augmentation"
    note for RandomErasing "Alias for Erasing with torchvision-compatible parameters"
Loading

File-Level Changes

Change Details Files
Added new Erasing transform class with optimized parameter calculation
  • Implemented mathematical derivation for calculating valid erasing parameters
  • Added support for different fill value types (constant, random, inpainting)
  • Included constraints handling for area and aspect ratio calculations
  • Added validation for scale and ratio parameters
albumentations/augmentations/dropout/coarse_dropout.py
Added torchvision-compatible RandomErasing alias
  • Created RandomErasing class that inherits from Erasing
  • Added parameter conversion from torchvision format
  • Included deprecation warning to encourage direct Erasing usage
albumentations/augmentations/tk/transform.py
Updated documentation and test coverage
  • Added Erasing and RandomErasing to the transforms table
  • Added test cases for both transforms
  • Included the transforms in mask and bbox compatibility tests
README.md
tests/aug_definitions.py
tests/test_core.py
tests/test_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 @ternaus - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

albumentations/augmentations/tk/transform.py Outdated Show resolved Hide resolved
tests/test_core.py Show resolved Hide resolved
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 96.22642% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.35%. Comparing base (b1a79c2) to head (d9848a3).
Report is 268 commits behind head on main.

Files with missing lines Patch % Lines
...mentations/augmentations/dropout/coarse_dropout.py 94.87% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2136       +/-   ##
=========================================
+ Coverage      0   90.35%   +90.35%     
=========================================
  Files         0       48       +48     
  Lines         0     7975     +7975     
=========================================
+ Hits          0     7206     +7206     
- Misses        0      769      +769     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ternaus ternaus merged commit 3e09e4b into main Nov 12, 2024
16 checks passed
@ternaus ternaus deleted the add_random_erasing branch November 12, 2024 02:58
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.

[New transform] Add RandomErasing
1 participant