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

Unify parameters #2160

Merged
merged 9 commits into from
Nov 20, 2024
Merged

Unify parameters #2160

merged 9 commits into from
Nov 20, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 20, 2024

Summary by Sourcery

Unify parameter names across transformation classes, deprecating old names and introducing new ones for consistency. Update documentation and tests to reflect these changes.

Enhancements:

  • Unify parameter names across various transformation classes to improve consistency and readability.
  • Deprecate old parameter names and introduce new ones, such as replacing 'value' with 'fill' and 'mask_value' with 'fill_mask'.
  • Add model validators to ensure deprecated fields are correctly mapped to new fields.

Documentation:

  • Update documentation to reflect changes in parameter names and usage, ensuring clarity for users.

Tests:

  • Modify tests to align with the new parameter naming conventions, ensuring they validate the updated functionality.

Copy link
Contributor

sourcery-ai bot commented Nov 20, 2024

Reviewer's Guide by Sourcery

This pull request unifies and standardizes parameter naming across various transforms in the library, particularly focusing on parameters related to border handling and fill values. The main changes involve renaming parameters to be more consistent, deprecating old parameter names while maintaining backward compatibility, and updating the documentation accordingly.

Class diagram for updated transform parameters

classDiagram
    class BaseDistortion {
        -interpolation: int
        -mask_interpolation: int
        +apply(img: np.ndarray, map_x: np.ndarray, map_y: np.ndarray, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, map_x: np.ndarray, map_y: np.ndarray, **params: Any): np.ndarray
    }
    class ElasticTransform {
        -interpolation: int
        -mask_interpolation: int
        +apply(img: np.ndarray, map_x: np.ndarray, map_y: np.ndarray, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, map_x: np.ndarray, map_y: np.ndarray, **params: Any): np.ndarray
    }
    class Perspective {
        -border_mode: int
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, matrix, max_width, max_height, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, matrix, max_width, max_height, **params: Any): np.ndarray
    }
    class Affine {
        -border_mode: int
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, matrix, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, matrix, **params: Any): np.ndarray
    }
    class Pad {
        -border_mode: BorderModeType
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, **params: Any): np.ndarray
    }
    class PadIfNeeded {
        -border_mode: int
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, **params: Any): np.ndarray
    }
    class Rotate {
        -border_mode: int
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, matrix, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, matrix, **params: Any): np.ndarray
    }
    class SafeRotate {
        -border_mode: int
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, matrix, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, matrix, **params: Any): np.ndarray
    }
    class CropAndPad {
        -border_mode: BorderModeType
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, crop_params: Sequence[int], pad_params: Sequence[int], **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, crop_params: Sequence[int], pad_params: Sequence[int], **params: Any): np.ndarray
    }
    class XYMasking {
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, **params: Any): np.ndarray
    }
    class CoarseDropout {
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, **params: Any): np.ndarray
    }
    class Erasing {
        -fill: ColorType
        -fill_mask: ColorType
        +apply(img: np.ndarray, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, **params: Any): np.ndarray
    }
    class MaskDropout {
        -fill: float | Literal["inpaint"]
        -fill_mask: float
        +apply(img: np.ndarray, dropout_mask: np.ndarray | None, **params: Any): np.ndarray
        +apply_to_mask(mask: np.ndarray, dropout_mask: np.ndarray | None, **params: Any): np.ndarray
    }
Loading

File-Level Changes

Change Details Files
Standardize border and fill value parameters across transforms
  • Rename 'value' to 'fill' for image fill values
  • Rename 'mask_value' to 'fill_mask' for mask fill values
  • Rename 'border_mode' to be consistent across all transforms
  • Add deprecation warnings for old parameter names
  • Update parameter validation logic to handle both old and new parameter names
albumentations/augmentations/geometric/transforms.py
albumentations/augmentations/geometric/rotate.py
albumentations/augmentations/crops/transforms.py
Remove redundant random transform classes
  • Remove RandomAffine in favor of Affine
  • Remove RandomErasing in favor of Erasing
  • Remove RandomRotation in favor of Rotate
  • Remove other redundant Random* classes
README.md
tests/test_augmentations.py
Update transform initialization and parameter handling
  • Standardize parameter order in init methods
  • Move p and always_apply parameters to end of parameter list
  • Update parameter validation in model schemas
  • Add proper type hints for parameters
albumentations/augmentations/dropout/transforms.py
albumentations/augmentations/geometric/resize.py
albumentations/core/transforms_interface.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 - here's some feedback:

Overall Comments:

  • Please document the transforms that were removed (like RandomRotation, RandomHorizontalFlip etc.) in the PR description, explaining the rationale for their removal. This will help users understand and adapt to the breaking changes.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 Complexity: 2 issues 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.

tests/test_serialization.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_dropout.py Show resolved Hide resolved
tests/functional/test_dropout.py Show resolved Hide resolved
tests/functional/test_dropout.py Show resolved Hide resolved
tests/functional/test_dropout.py Show resolved Hide resolved
tests/functional/test_dropout.py Show resolved Hide resolved
tests/functional/test_dropout.py Show resolved Hide resolved
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 93.77593% with 15 lines in your changes missing coverage. Please review.

Project coverage is 89.72%. Comparing base (b1a79c2) to head (858eccb).
Report is 292 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/augmentations/crops/transforms.py 92.10% 6 Missing ⚠️
...bumentations/augmentations/geometric/transforms.py 93.58% 5 Missing ⚠️
albumentations/augmentations/dropout/xy_masking.py 80.00% 2 Missing ⚠️
albumentations/augmentations/geometric/rotate.py 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2160       +/-   ##
=========================================
+ Coverage      0   89.72%   +89.72%     
=========================================
  Files         0       47       +47     
  Lines         0     8469     +8469     
=========================================
+ Hits          0     7599     +7599     
- Misses        0      870      +870     

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


🚨 Try these New Features:

@ternaus ternaus merged commit 626e737 into main Nov 20, 2024
16 checks passed
@ternaus ternaus deleted the unify_parameters branch November 20, 2024 18:24
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.

1 participant