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 transforms #2147

Merged
merged 4 commits into from
Nov 17, 2024
Merged

Add transforms #2147

merged 4 commits into from
Nov 17, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 17, 2024

Fixes: #2111

Summary by Sourcery

Refactor the 'Solarize' transform to use a 'threshold_range' parameter for more flexible threshold specification and introduce a new 'RandomSolarize' transform for compatibility with Kornia API naming conventions. Update tests and documentation accordingly, and adjust the 'setup.py' to require a newer version of 'pydantic'.

New Features:

  • Introduce a new transform class 'RandomSolarize' as an alias for 'Solarize', compatible with Kornia API naming conventions.

Enhancements:

  • Refactor the 'Solarize' transform to use 'threshold_range' instead of 'threshold', allowing for more flexible threshold specification as a fraction of the maximum value.

Documentation:

  • Add 'RandomSolarize' to the list of pixel-level transforms in the README.

Tests:

  • Update tests for the 'Solarize' function to accommodate the new 'threshold_range' parameter and ensure compatibility with both uint8 and float32 image types.

Chores:

  • Update the 'setup.py' to require a newer version of 'pydantic' (>=2.9.2).

Summary by Sourcery

Refactor the 'Solarize' transform to use a 'threshold_range' parameter for more flexible threshold specification and introduce a new 'RandomSolarize' transform for compatibility with Kornia API naming conventions. Update tests and documentation accordingly.

New Features:

  • Introduce a new transform class 'RandomSolarize' as an alias for 'Solarize', compatible with Kornia API naming conventions but using Albumentations' parameter format.

Enhancements:

  • Refactor the 'Solarize' transform to use 'threshold_range' instead of 'threshold', allowing for more flexible threshold specification as a fraction of the maximum value.

Documentation:

  • Update README to include 'RandomSolarize' in the list of pixel-level transforms.

Tests:

  • Revise tests for the 'Solarize' function to accommodate the new 'threshold_range' parameter and add tests for the 'RandomSolarize' transform.

Chores:

  • Update the 'pydantic' dependency version in 'setup.py' from '>=2.7.0' to '>=2.9.2'.

Copy link
Contributor

sourcery-ai bot commented Nov 17, 2024

Reviewer's Guide by Sourcery

The PR refactors the Solarize transform to use normalized threshold values and introduces a new RandomSolarize transform for Kornia API compatibility. The main changes involve modifying the threshold parameter to use a normalized range [0,1] instead of absolute values, improving the handling of both uint8 and float32 images, and adding comprehensive documentation.

Class diagram for Solarize and RandomSolarize transforms

classDiagram
    class Solarize {
        - threshold: ScaleFloatType | None
        + threshold_range: tuple[float, float]
        + apply(img: np.ndarray, threshold: float) np.ndarray
        + get_params() dict[str, float]
        + get_transform_init_args_names() tuple[str, ...]
    }
    class RandomSolarize {
        + thresholds: tuple[float, float]
        + get_transform_init_args_names() tuple[str, ...]
    }
    Solarize <|-- RandomSolarize
    note for Solarize "Refactored to use threshold_range instead of threshold"
    note for RandomSolarize "New class introduced for Kornia API compatibility"
Loading

File-Level Changes

Change Details Files
Refactor Solarize transform to use normalized threshold values
  • Replace 'threshold' parameter with 'threshold_range' using normalized [0,1] range
  • Add backward compatibility for legacy threshold parameter
  • Update threshold calculation to scale based on image type (uint8 or float32)
  • Improve documentation with detailed examples and mathematical formulation
albumentations/augmentations/transforms.py
albumentations/augmentations/functional.py
Add new RandomSolarize transform for Kornia compatibility
  • Create RandomSolarize class inheriting from Solarize
  • Add warning message about differences from Kornia implementation
  • Add documentation explaining parameter differences and usage examples
albumentations/augmentations/tk/transform.py
Update tests to accommodate new threshold handling
  • Refactor solarize functional tests to use normalized thresholds
  • Add tests for RandomSolarize transform
  • Update serialization tests to handle deprecated fields
tests/functional/test_functional.py
tests/test_serialization.py
tests/aug_definitions.py
tests/test_augmentations.py
Update project configuration and documentation
  • Update pydantic requirement to version >=2.9.2
  • Add RandomSolarize to pixel-level transforms in README
setup.py
README.md

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

@ternaus ternaus marked this pull request as draft November 17, 2024 21:33
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: 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.

albumentations/augmentations/functional.py Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
albumentations/augmentations/transforms.py Show resolved Hide resolved
albumentations/augmentations/tk/transform.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.38%. Comparing base (b1a79c2) to head (25634c8).
Report is 279 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2147       +/-   ##
=========================================
+ Coverage      0   90.38%   +90.38%     
=========================================
  Files         0       48       +48     
  Lines         0     8084     +8084     
=========================================
+ Hits          0     7307     +7307     
- Misses        0      777      +777     

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

@ternaus ternaus marked this pull request as ready for review November 17, 2024 21:37
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: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 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.

albumentations/augmentations/tk/transform.py Show resolved Hide resolved
albumentations/augmentations/functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
@ternaus ternaus merged commit 30697e7 into main Nov 17, 2024
16 checks passed
@ternaus ternaus deleted the add_transforms branch November 17, 2024 22:20
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 RandomSolarize
1 participant