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

Fix padding #1856

Merged
merged 9 commits into from
Jul 24, 2024
Merged

Fix padding #1856

merged 9 commits into from
Jul 24, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Jul 24, 2024

Fixes #1853

Summary by Sourcery

This pull request addresses padding issues and refactors the elastic transformation functionality. It introduces new functions for precise and approximate elastic transformations, improves the handling of border values, and updates the ElasticTransform class to remove deprecated parameters. Additionally, new tests are added to ensure the correctness of these changes.

  • New Features:
    • Introduced elastic_transform_precise and elastic_transform_approximate functions for precise and approximate elastic transformations respectively.
    • Added warp_affine_with_value_extension and copy_make_border_with_value_extension functions to handle extended border values.
  • Bug Fixes:
    • Fixed padding issues by ensuring consistent handling of border values across different functions.
  • Enhancements:
    • Refactored the elastic_transform function to delegate to either elastic_transform_precise or elastic_transform_approximate based on the approximate parameter.
    • Updated ElasticTransform class to remove the alpha_affine parameter and deprecated its usage, suggesting the use of the Affine transform instead.
    • Improved the handling of padding values by introducing the extend_value function to ensure correct padding for multi-channel images.
    • Revised the ElasticTransform class to provide clearer documentation and parameter descriptions.
  • Tests:
    • Added new tests to verify the correct handling of padding values across different numbers of channels.
    • Updated existing tests to align with the refactored elastic_transform function and the removal of the alpha_affine parameter.

Copy link
Contributor

sourcery-ai bot commented Jul 24, 2024

Reviewer's Guide by Sourcery

This pull request refactors the elastic transformation functions, updates the ElasticTransform class to remove the alpha_affine parameter, and improves padding handling. It also updates tests and serialization files accordingly, and adds new tests for padding color. Additionally, it refactors parameter handling in crop and pad functions and updates valid interpolation and border modes.

File-Level Changes

Files Changes
albumentations/augmentations/geometric/functional.py
albumentations/augmentations/geometric/transforms.py
Refactored elastic transformation functions and updated ElasticTransform class to remove alpha_affine parameter and improve padding handling.
tests/test_transforms.py
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
tests/test_serialization.py
Updated tests and serialization files to remove alpha_affine parameter and added new tests for padding color.
albumentations/augmentations/crops/transforms.py
albumentations/augmentations/crops/functional.py
Updated crop and pad functions to use ScalarType for pad_value and improved parameter handling.
albumentations/augmentations/geometric/rotate.py
albumentations/core/pydantic.py
Refactored parameter handling and updated valid interpolation and border modes.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

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:

  • Consider adding unit tests for the new elastic_transform_precise and elastic_transform_approximate functions to ensure they behave as expected.
  • The removal of alpha_affine parameter might be a breaking change. Consider adding a deprecation warning if this parameter is provided, to ease the transition for existing users.
Here's what I looked at during the review
  • 🟡 General issues: 6 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 to tell me if it was helpful.

albumentations/augmentations/geometric/functional.py Outdated Show resolved Hide resolved
albumentations/augmentations/geometric/functional.py Outdated Show resolved Hide resolved
tests/test_transforms.py Show resolved Hide resolved
tests/test_transforms.py Show resolved Hide resolved
tests/test_transforms.py Show resolved Hide resolved
albumentations/augmentations/geometric/functional.py Outdated Show resolved Hide resolved
@ternaus ternaus merged commit 8244a4b into main Jul 24, 2024
17 checks passed
@ternaus ternaus deleted the fix_padding branch August 5, 2024 22:34
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.

How is the pad_cval defined of CropAndPad?
1 participant