Skip to content

Fix OBB IoU for non-square canvases#2282

Merged
Borda merged 5 commits into
roboflow:developfrom
RitwijParmar:codex/fix-obb-iou-metrics
Jun 1, 2026
Merged

Fix OBB IoU for non-square canvases#2282
Borda merged 5 commits into
roboflow:developfrom
RitwijParmar:codex/fix-obb-iou-metrics

Conversation

@RitwijParmar

Copy link
Copy Markdown
Contributor

Summary

  • fix oriented_box_iou_batch canvas sizing so x coordinates determine width and y coordinates determine height
  • add a scale-invariance regression for non-square oriented boxes
  • add downstream metric coverage proving perfect non-square OBB predictions score correctly for Precision, Recall, F1, mAP, and mAR

Fixes #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

@RitwijParmar RitwijParmar requested a review from SkalskiP as a code owner May 29, 2026 17:47
@CLAassistant

CLAassistant commented May 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79%. Comparing base (fb02e5c) to head (94835c9).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/metrics/test_oriented_bounding_box_metrics.py Outdated
Comment thread tests/metrics/test_mean_average_precision.py
Borda and others added 4 commits June 1, 2026 00:44
- 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 Borda merged commit 7d22596 into roboflow:develop Jun 1, 2026
26 checks passed
@Borda Borda mentioned this pull request Jun 11, 2026
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>
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.

[Bug]: oriented_box_iou_batch returns 0 for non-square inputs, breaking all OBB metrics

4 participants