Add OBB support to ConfusionMatrix via MetricTarget#2247
Open
Khanz9664 wants to merge 6 commits into
Open
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2247 +/- ##
=======================================
Coverage 78% 78%
=======================================
Files 66 66
Lines 8347 8370 +23
=======================================
+ Hits 6475 6510 +35
+ Misses 1872 1860 -12 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds OBB support to ConfusionMatrix by threading a metric_target parameter through detections_to_tensor, validate_input_tensors, ConfusionMatrix.from_detections/from_tensors/evaluate_detection_batch/benchmark. When MetricTarget.ORIENTED_BOUNDING_BOXES is selected, IoU is computed via oriented_box_iou_batch over xyxyxyxy data; MetricTarget.MASKS is explicitly rejected.
Changes:
- Extend
detections_to_tensorto emit (N,9)/(N,10) OBB tensors fromdata["xyxyxyxy"]and rejectMASKS. - Update
validate_input_tensorsandevaluate_detection_batchto use OBB-aware column layout and dispatch tooriented_box_iou_batch. - Plumb
metric_targetthroughConfusionMatrixdataclass,from_detections,from_tensors, andbenchmark; update docstrings. - Add OBB tensor-extraction parametrizations and an OBB rotation-sensitivity end-to-end test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/supervision/metrics/detection.py | Adds OBB-aware tensor extraction, validation, IoU dispatch and a new metric_target field plumbed through the public APIs. |
| tests/metrics/test_detection.py | Adds OBB cases for detections_to_tensor, validation tests for OBB shapes, and a from_detections OBB rotation-sensitivity test. |
…idation - Dispatch to oriented_box_iou_batch when metric_target=ORIENTED_BOUNDING_BOXES - Raise ValueError (not NotImplementedError) for MetricTarget.MASKS on all entry points (from_detections, from_tensors, evaluate_detection_batch) via _assert_supported_target helper - Validate OBB array shape before reshape; clear error message on malformed data - Add regression test for roboflow#1760 (orthogonal thin bars: AABB IoU=1.0 but OBB IoU≈0.053) - Add parametrized tests: from_tensors OBB end-to-end, MASKS rejection, multiclass OBB, metric_target persistence - Update docstrings: detections_to_tensor shape table, from_detections non-trivial example, metric_target param docs across public API - Add changelog entry for PR roboflow#2247 under 0.28.0 --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Refactor ConfusionMatrix test cases for MASKS metric target into reusable helper functions (_call_confusion_matrix_from_detections_masks, _call_confusion_matrix_from_tensors_masks, _call_confusion_matrix_evaluate_detection_batch_masks). - Update test parametrization to use extracted helper functions for improved clarity and maintainability. - Simplify docstring examples to Python REPL (pycon) output format for consistency.
…664/supervision into feat/obb-confusion-matrix
Borda
previously approved these changes
May 13, 2026
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.
Before submitting
Description
Adds Oriented Bounding Box (OBB) support to
ConfusionMatrixby aligning it with the existingMetricTargetpattern used across other metrics.Currently,
ConfusionMatrixcomputes IoU usingbox_iou_batch, meaning OBB detections are effectively evaluated using derived axis-aligned bounding boxes (AABB). This PR enables correct OBB evaluation throughoriented_box_iou_batch.The implementation preserves full backward compatibility for existing AABB workflows and introduces explicit handling for unsupported
MetricTarget.MASKS.Type of Change
Motivation and Context
ConfusionMatrixcurrently lacks OBB support, even though other metrics (e.g., Precision, Recall, F1 Score) already supportMetricTarget.ORIENTED_BOUNDING_BOXES.As a result, users working with OBB detections may assume IoU is computed using rotated boxes, while it is actually computed using derived AABB coordinates via
box_iou_batch.This PR aligns
ConfusionMatrixwith the existing metric architecture and ensures correct OBB evaluation.Closes #1760
Changes Made
metric_targetsupport toConfusionMatrixdetections_to_tensorto support OBB tensor extraction fromxyxyxyxy(N, 9)target tensors and(N, 10)prediction tensorsoriented_box_iou_batchfor OBB IoU computationMetricTarget.MASKSTesting
Tests executed locally:
Results:
Google Colab (optional)
Not applicable.
Screenshots/Videos (optional)
Not applicable.
Additional Notes
This implementation intentionally reuses the existing
oriented_box_iou_batchutility and follows the establishedMetricTargetpattern used by other metrics to minimize architectural changes and preserve consistency.