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 box filtering #2001

Merged
merged 3 commits into from
Oct 19, 2024
Merged

Fix box filtering #2001

merged 3 commits into from
Oct 19, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Oct 19, 2024

Fixes: #1999

Summary by Sourcery

Fix box filtering logic and enhance the RandomResizedCrop transformation with additional validators. Add a test to verify the correct handling of bounding boxes and labels in the RandomResizedCrop transformation.

Bug Fixes:

  • Fix box filtering logic to correctly process data fields and handle empty keypoints arrays.

Enhancements:

  • Enhance the RandomResizedCrop transformation by adding validators to ensure non-decreasing scale and ratio parameters.

Tests:

  • Add a test for the RandomResizedCrop transformation to ensure correct handling of bounding boxes and labels.

Copy link
Contributor

sourcery-ai bot commented Oct 19, 2024

Reviewer's Guide by Sourcery

This pull request addresses an issue with box filtering in the Albumentations library. The changes primarily focus on refactoring the postprocessing logic in the core utils, improving the handling of empty keypoints, and enhancing the RandomResizedCrop transform. The modifications aim to fix a reported issue and improve the overall robustness of the library.

Updated class diagram for postprocessing logic

classDiagram
    class Postprocessor {
        +postprocess(data: dict[str, Any]) dict[str, Any]
        +_process_data_fields(data: dict[str, Any], image_shape: tuple[int, int]) dict[str, Any]
        +_process_single_field(data_name: str, field_data: Any, image_shape: tuple[int, int]) Any
        +_create_empty_keypoints_array() np.ndarray
        +_convert_sequence_inputs(data: dict[str, Any]) dict[str, Any]
    }
    note for Postprocessor "Refactored to improve handling of empty keypoints and sequence inputs"
Loading

Updated class diagram for RandomResizedCrop

classDiagram
    class RandomResizedCrop {
        +InitSchema
    }
    class InitSchema {
        +scale: Annotated[tuple[float, float], AfterValidator(check_01), AfterValidator(nondecreasing)]
        +ratio: Annotated[tuple[float, float], AfterValidator(check_0plus), AfterValidator(nondecreasing)]
        +width: int | None
    }
    note for InitSchema "Enhanced with nondecreasing validator for scale and ratio"
Loading

File-Level Changes

Change Details Files
Refactored postprocessing logic in core utils
  • Split postprocess method into smaller, more focused methods
  • Introduced _process_data_fields and _process_single_field methods
  • Created a separate method for handling empty keypoints arrays
  • Moved sequence input conversion to a dedicated method
albumentations/core/utils.py
Added a new test for RandomResizedCrop transform
  • Created test_random_resized_crop function
  • Verified that the number of bounding boxes matches the number of labels after transformation
tests/test_bbox.py
Updated RandomResizedCrop transform initialization
  • Added nondecreasing validator to scale and ratio parameters
  • Deprecated 'height' and 'width' parameters in favor of 'size'
albumentations/augmentations/crops/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 - here's some feedback:

Overall Comments:

  • Consider adding a note in the documentation about the changes to the InitSchema class, particularly the addition of the nondecreasing validator for 'scale' and 'ratio' parameters. This will help users understand the new constraints and potential impacts on existing code.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues 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.

albumentations/core/utils.py Show resolved Hide resolved
albumentations/core/utils.py Show resolved Hide resolved
tests/test_bbox.py Show resolved Hide resolved
@ternaus ternaus merged commit 20098f4 into main Oct 19, 2024
14 checks passed
@ternaus ternaus deleted the fix_box_filtering branch October 19, 2024 02:17
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.

label_fields are not filtered out with bboxes
1 participant