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 time masking #2122

Merged
merged 4 commits into from
Nov 8, 2024
Merged

Add time masking #2122

merged 4 commits into from
Nov 8, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 8, 2024

Fixes: #2074

Summary by Sourcery

Add the TimeMasking transform to the library, allowing for time domain masking of spectrograms. Fix issues related to empty 'holes' arrays in transformations. Enhance user guidance with warnings about transform usage and update documentation to reflect new features.

New Features:

  • Introduce the TimeMasking transform to apply masking to spectrograms in the time domain, enhancing model robustness against temporal variations.

Bug Fixes:

  • Fix the issue where transformations would fail if the 'holes' array was empty by adding checks to return the original data in such cases.

Enhancements:

  • Add warnings to inform users about the alias nature of TimeReverse and the specialized nature of TimeMasking, suggesting alternatives for more flexibility.

Documentation:

  • Update README to include documentation for the new TimeMasking transform.

Tests:

  • Add test cases for the new TimeMasking transform to ensure its correct functionality.

Copy link
Contributor

sourcery-ai bot commented Nov 8, 2024

Reviewer's Guide by Sourcery

This PR introduces a new TimeMasking transform for spectrograms, which is implemented as a specialized version of XYMasking. The implementation also includes bug fixes for handling empty holes in dropout-based transforms and adds deprecation warnings for TimeReverse transform.

Class diagram for the new TimeMasking transform

classDiagram
    class XYMasking {
        <<abstract>>
        +apply(img: np.ndarray, holes: np.ndarray, seed: int, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, holes: np.ndarray, seed: int, **params: Any): np.ndarray
        +apply_to_bboxes(bboxes: np.ndarray, holes: np.ndarray, **params: Any): np.ndarray
        +apply_to_keypoints(keypoints: np.ndarray, holes: np.ndarray, **params: Any): np.ndarray
    }

    class TimeMasking {
        +time_mask_param: int
        +apply(img: np.ndarray, holes: np.ndarray, seed: int, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, holes: np.ndarray, seed: int, **params: Any): np.ndarray
        +apply_to_bboxes(bboxes: np.ndarray, holes: np.ndarray, **params: Any): np.ndarray
        +apply_to_keypoints(keypoints: np.ndarray, holes: np.ndarray, **params: Any): np.ndarray
        +get_transform_init_args_names(): tuple[str, ...]
    }

    XYMasking <|-- TimeMasking
    note for TimeMasking "TimeMasking is a specialized version of XYMasking for time domain masking."
Loading

File-Level Changes

Change Details Files
Implemented TimeMasking transform for spectrogram augmentation
  • Created new TimeMasking class that inherits from XYMasking
  • Configured transform to apply masking only in time domain
  • Added parameter validation using Pydantic Field
  • Added comprehensive documentation with references to SpecAugment paper
albumentations/augmentations/spectrogram/transform.py
Fixed edge cases in dropout-based transforms when no holes are present
  • Added checks for empty holes array in apply methods
  • Return original data unchanged when holes array is empty
  • Applied fix to image, mask, bbox, and keypoint processors
albumentations/augmentations/dropout/transforms.py
Added deprecation warning for TimeReverse transform
  • Added warning message suggesting use of HorizontalFlip instead
  • Updated documentation to indicate TimeReverse is an alias
albumentations/augmentations/spectrogram/transform.py
Updated test suite and documentation
  • Added TimeMasking to test cases
  • Updated README with TimeMasking transform entry
  • Fixed return type annotation in Snow transform
tests/test_transforms.py
tests/aug_definitions.py
README.md
albumentations/augmentations/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: 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.

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.24%. Comparing base (b1a79c2) to head (50a701a).
Report is 256 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2122       +/-   ##
=========================================
+ Coverage      0   90.24%   +90.24%     
=========================================
  Files         0       47       +47     
  Lines         0     7738     +7738     
=========================================
+ Hits          0     6983     +6983     
- Misses        0      755      +755     

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

@ternaus ternaus merged commit d538952 into main Nov 8, 2024
16 checks passed
@ternaus ternaus deleted the add_time_masking branch November 8, 2024 23:06
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 TimeMasking
1 participant