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 in BBox clipping #2310

Merged
merged 1 commit into from
Jan 27, 2025
Merged

Fix in BBox clipping #2310

merged 1 commit into from
Jan 27, 2025

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Jan 27, 2025

Fixes: #2309

Summary by Sourcery

Bug Fixes:

  • Fix issues with bounding box clipping when using the "yolo", "coco", or "pascal_voc" formats.

Copy link
Contributor

sourcery-ai bot commented Jan 27, 2025

Reviewer's Guide by Sourcery

This pull request addresses a bug in bounding box clipping where class IDs were being incorrectly modified when clipping was enabled. The fix ensures that bounding boxes are clipped to the image boundaries without altering the associated class labels or scores. Additionally, comprehensive tests have been added to cover various bounding box formats, edge cases, and data types.

Sequence diagram for BBox clipping process

sequenceDiagram
    participant C as Client
    participant BU as BBoxUtils
    participant LF as LabelField

C->>BU: check_and_convert(bbox_data)
BU->>BU: convert_bbox_format()
BU->>BU: clip_bbox_coordinates()
Note over BU: Only clip x,y coordinates
Note over BU: Preserve class IDs/scores
BU->>BU: filter_invalid_bboxes()
BU-->>C: return processed_bboxes
Loading

Class diagram for BBox and Label Field handling

classDiagram
    class BBoxUtils {
        +params
        +check_and_convert(data)
        -clip_bbox_coordinates()
        -filter_invalid_bboxes()
    }

    class LabelFieldEncoder {
        +is_numerical_label: dict
        +label_encoders: dict
        +_encode_label_field(data, data_name, label_field)
        +_validate_label_field_length(data, data_name, label_field)
    }

    note for BBoxUtils "Modified clipping to preserve class IDs"
    note for LabelFieldEncoder "Enhanced numerical type handling"
Loading

File-Level Changes

Change Details Files
Added comprehensive test cases for bounding box clipping with various formats, edge cases, and data types.
  • Added parameterized tests for 'yolo', 'coco', and 'pascal_voc' formats.
  • Included tests for empty bounding box arrays.
  • Added tests for single bounding boxes with high class IDs.
  • Added tests for edge cases such as very small and very large bounding boxes.
  • Included tests for different numpy data types for class labels and scores.
  • Added a specific test case to reproduce the class ID clipping bug.
  • Added tests for very high and very low confidence scores.
  • Added tests for multiple label fields with different numpy dtypes.
tests/test_bbox.py
Fixed the bounding box clipping logic to prevent modification of class IDs.
  • Modified the clipping logic to only clip the bounding box coordinates and not the class IDs or scores.
  • Added a check to ensure clipping is only applied if there are bounding boxes.
albumentations/core/bbox_utils.py
Modified the label encoding logic to handle numpy arrays and preserve data types.
  • Modified the _encode_label_field method to handle numpy arrays directly.
  • Preserve the numpy array dtype when encoding numerical label fields.
  • Added a check to see if the input is a numpy array before converting to float32.
albumentations/core/utils.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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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: all looks good
  • 🟢 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.

tests/test_bbox.py Show resolved Hide resolved
tests/test_bbox.py Show resolved Hide resolved
tests/test_bbox.py Show resolved Hide resolved
Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.83%. Comparing base (b1a79c2) to head (3c633d8).
Report is 394 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2310       +/-   ##
=========================================
+ Coverage      0   89.83%   +89.83%     
=========================================
  Files         0       50       +50     
  Lines         0     9017     +9017     
=========================================
+ Hits          0     8100     +8100     
- Misses        0      917      +917     
Flag Coverage Δ
ubuntu-py3.12 89.83% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ternaus ternaus merged commit 188a917 into main Jan 27, 2025
16 checks passed
@ternaus ternaus deleted the fix_bbox_clip branch January 27, 2025 23:40
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.

CRITICAL BUG! v2 is clipping bounding boxes classes when BboxParams.clip = True
1 participant