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

Update longest and shortest maxsize #2209

Merged
merged 5 commits into from
Dec 20, 2024
Merged

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Dec 20, 2024

Summary by Sourcery

Refactor LongestMaxSize and SmallestMaxSize transforms to inherit from a common base class MaxSizeTransform. Introduce max_size_hw parameter for specifying resize constraints by height and width. Update tests and functional implementations accordingly.

New Features:

  • Add max_size_hw parameter to LongestMaxSize and SmallestMaxSize to support resizing by height and width constraints.

Tests:

  • Update tests to cover the new max_size_hw parameter and refactor existing tests.

Copy link
Contributor

sourcery-ai bot commented Dec 20, 2024

Reviewer's Guide by Sourcery

This pull request refactors the LongestMaxSize and SmallestMaxSize transforms to inherit from a new base class MaxSizeTransform. It also updates the parameter validation logic and adds support for specifying maximum sizes as (height, width) tuples using the max_size_hw parameter.

Class diagram showing the new MaxSizeTransform hierarchy

classDiagram
    class DualTransform {
        <<abstract>>
    }
    class MaxSizeTransform {
        <<abstract>>
        +max_size: int|list[int]|None
        +max_size_hw: tuple[int|None, int|None]|None
        +interpolation: int
        +mask_interpolation: int
        +apply(img, scale)
        +apply_to_mask(mask, scale)
        +apply_to_keypoints(keypoints, scale)
    }
    class LongestMaxSize {
        +get_params_dependent_on_data()
    }
    class SmallestMaxSize {
        +get_params_dependent_on_data()
    }
    DualTransform <|-- MaxSizeTransform
    MaxSizeTransform <|-- LongestMaxSize
    MaxSizeTransform <|-- SmallestMaxSize
    note for MaxSizeTransform "New base class that handles
common resize functionality"
    note for LongestMaxSize "Scales based on longest side"
    note for SmallestMaxSize "Scales based on smallest side"
Loading

File-Level Changes

Change Details Files
Introduce MaxSizeTransform base class and refactor LongestMaxSize and SmallestMaxSize to inherit from it.
  • Created a new base class MaxSizeTransform for transforms that resize based on maximum size constraints.
  • Refactored LongestMaxSize and SmallestMaxSize to inherit from MaxSizeTransform.
  • Moved common logic for resizing and applying transforms to different targets to the base class.
  • Added max_size_hw parameter to allow specifying maximum size as a (height, width) tuple.
  • Updated parameter validation to ensure either max_size or max_size_hw is specified, but not both.
albumentations/augmentations/geometric/resize.py
Update tests for LongestMaxSize and SmallestMaxSize.
  • Added tests to verify the behavior of LongestMaxSize and SmallestMaxSize with the new max_size_hw parameter.
  • Added tests for different combinations of input shapes and maximum size constraints.
  • Ensured existing tests still pass with the refactored implementation.
tests/test_transforms.py
Update functional tests for image resizing and keypoint transformations.
  • Updated tests to use np.testing.assert_array_equal for stricter comparison of arrays.
  • Added tests for keypoint transformations after resizing.
  • Added tests for LongestMaxSize and SmallestMaxSize keypoint transformations.
  • Moved keypoint transformation tests from test_transforms.py to test_keypoint.py.
tests/functional/test_functional.py
tests/test_keypoint.py
Remove deprecated functions and update usages.
  • Removed deprecated functions longest_max_size and smallest_max_size.
  • Updated usages of these functions to use the new MaxSizeTransform base class and its methods.
albumentations/augmentations/geometric/functional.py
Update documentation and coding guidelines.
  • Added guidelines for updating transform documentation in the README.
docs/contributing/coding_guidelines.md
Update tests for 3D volumes and masks.
  • Updated tests to use np.testing.assert_allclose for comparing image and volume data with tolerance.
tests/transforms3d/test_transforms.py
Update deprecated parameters in PadIfNeeded transform.
  • Deprecated parameters pad_mode, pad_cval, and pad_cval_mask in PadIfNeeded transform.
  • Added border_mode, fill, and fill_mask parameters as replacements.
  • Updated validation logic to handle deprecated parameters and issue warnings.
albumentations/augmentations/crops/transforms.py
Update tests for core functionalities.
  • Updated tests to reflect changes in parameter names and usage.
  • Added tests for elastic transform and mask interpolation.
tests/test_core.py
Update deprecated parameters in GaussNoise transform.
  • Deprecated var_limit parameter in GaussNoise transform.
  • Added std_range parameter as a replacement.
  • Updated validation logic to handle the deprecated parameter and issue a warning.
albumentations/augmentations/transforms.py
Update pre-commit configuration.
  • Updated ruff version to v0.8.4.
.pre-commit-config.yaml
Remove unused fixtures and imports.
  • Removed unused fixtures and imports to clean up the test suite.
tests/conftest.py
Update transform serialization files.
  • Updated transform serialization files to reflect changes in transform parameters and behavior.
tests/files/transform_serialization_v2_with_totensor.json
tests/files/transform_serialization_v2_without_totensor.json
tests/files/transform_v1.1.0_with_totensor.json
tests/files/transform_v1.1.0_without_totensor.json

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: all looks good
  • 🟡 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/geometric/resize.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 91.95402% with 7 lines in your changes missing coverage. Please review.

Project coverage is 89.28%. Comparing base (b1a79c2) to head (d3796e6).
Report is 320 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/augmentations/geometric/resize.py 94.87% 4 Missing ⚠️
albumentations/augmentations/crops/transforms.py 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2209       +/-   ##
=========================================
+ Coverage      0   89.28%   +89.28%     
=========================================
  Files         0       50       +50     
  Lines         0     8982     +8982     
=========================================
+ Hits          0     8020     +8020     
- Misses        0      962      +962     

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

@ternaus ternaus merged commit f7865ff into main Dec 20, 2024
16 checks passed
@ternaus ternaus deleted the update_LongestAnd_ShortestMaxsize branch December 20, 2024 01:57
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