Fix OBB IoU for non-square canvases#2282
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2282 +/- ##
=======================================
+ Coverage 79% 79% +1%
=======================================
Files 66 66
Lines 8567 8569 +2
=======================================
+ Hits 6726 6806 +80
+ Misses 1841 1763 -78 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes OBB IoU rasterization for non-square canvases by deriving canvas width from x coordinates and height from y coordinates, preventing clipped masks for wide/tall oriented boxes.
Changes:
- Corrects width/height calculation in
oriented_box_iou_batch. - Adds a direct non-square scaling regression test for OBB IoU.
- Adds downstream OBB metric regression coverage, including precision/recall/F1/mAR and attempted mAP coverage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/supervision/detection/utils/iou_and_nms.py |
Fixes OBB mask canvas dimensions. |
tests/detection/utils/test_iou_and_nms.py |
Adds OBB IoU non-square scale-invariance regression. |
tests/metrics/test_oriented_bounding_box_metrics.py |
Adds parametrized downstream OBB metric checks. |
tests/metrics/test_mean_average_precision.py |
Adds non-square OBB mAP regression test. |
- Remove MeanAveragePrecision from OBB IoU parametrize: MAP uses COCO evaluator path (box_iou_batch_with_jaccard), never routes through oriented_box_iou_batch regardless of metric_target; parametrizing it implied OBB IoU correctness that MAP does not exercise - Add test_mean_average_precision_accepts_obb_metric_target smoke test with explicit NOTE documenting the COCO evaluator path --- Co-authored-by: Claude Code <noreply@anthropic.com>
Docstring was misleading — "must not fail" implied correctness verification. MAP uses COCO evaluator path (box_iou_batch_with_jaccard) and never calls oriented_box_iou_batch; test validates API acceptance and xyxy-based IoU, not OBB IoU correctness. --- Co-authored-by: Claude Code <noreply@anthropic.com>
Add [[1,10]] (tall box) alongside existing [[10,1]] (wide box) to cover both axis-dominance directions. Add docstring explaining the regression guard and rasterization tolerance rationale. --- Co-authored-by: Claude Code <noreply@anthropic.com>
…_batch - Return zeros matrix early when either input is empty, avoiding ValueError from calling .max() on empty array - Document [..., 0] = x-coordinates, [..., 1] = y-coordinates axis convention in Args docstring and inline comment above canvas sizing - Add CHANGELOG entry for PR roboflow#2282 OBB canvas dimension fix --- Co-authored-by: Claude Code <noreply@anthropic.com>
Borda
approved these changes
Jun 1, 2026
Closed
Borda
added a commit
that referenced
this pull request
Jun 16, 2026
- Merge Added [#2312] + Changed [#2312] into single Added entry covering xyxyxyxy_to_xyxy utility and with_nmm OBB merge - Merge Fixed [#2282] + Fixed [#2317] into single entry [#2282, #2317]; #2317 replaced the rasterization approach from #2282 entirely - Fold Fixed [#2252] into Added [#2252]; same function, one entry covers both preserve_audio feature and muxing bug fixes - Fold Fixed [#2289] into Added [#2302, #2289]; same function, one entry covers both is_obb parameter and rotation-loss fix --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
oriented_box_iou_batchcanvas sizing so x coordinates determine width and y coordinates determine heightFixes #2278.
Why this matters
OBB evaluation currently rasterizes polygons onto a canvas with width/height swapped. For non-square extents this can clip the polygons away and return zero IoU, which then makes otherwise correct OBB detections look like complete failures across the metrics stack. This is especially painful for real-world CV datasets where rotated boxes are common for aerial imagery, floorplans, traffic scenes, and industrial inspection.
Tests
.venv/bin/python -m ruff check src/supervision/detection/utils/iou_and_nms.py tests/detection/utils/test_iou_and_nms.py tests/metrics/test_mean_average_precision.py tests/metrics/test_oriented_bounding_box_metrics.py.venv/bin/python -m pytest tests/detection/utils/test_iou_and_nms.py::test_oriented_box_iou_batch_is_invariant_to_non_square_scaling tests/metrics/test_oriented_bounding_box_metrics.py.venv/bin/python -m pytest tests/detection/utils/test_iou_and_nms.py tests/metrics/test_oriented_bounding_box_metrics.py tests/metrics/test_mean_average_precision.py tests/metrics/test_mean_average_recall.py tests/metrics/test_precision.py tests/metrics/test_recall.py tests/metrics/test_f1_score.py