Enhancement/add obb support confusion matrix
Description
This pull request introduces support for evaluating oriented bounding boxes (OBBs) in the confusion matrix calculations within the supervision library. The changes include adding a new parameter to enable OBB support, modifying the IoU calculation logic, and adding comprehensive tests to validate the functionality.
Enhancements to IoU and Confusion Matrix Calculations:
- Added the
use_oriented_boxesparameter to thefrom_detections,from_tensors, andevaluate_detection_batchmethods, allowing users to toggle between axis-aligned and oriented bounding box IoU calculations. - Updated the IoU computation logic to use
oriented_box_iou_batchwhenuse_oriented_boxesis set toTrue. This ensures accurate IoU calculations for OBBs.
Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [x] This change requires a documentation update
How has this change been tested, please provide a testcase or example of how you tested the change?
Added a new test file, test/metrics/test_confusion_matrix_obb.py, to validate the confusion matrix functionality with and without OBB support. These tests include scenarios for perfect matches and slight offsets between predictions and ground truth.
Docs
- [x] Docs updated? What were the changes:
- Enhanced the example in the
from_detectionsmethod's docstring to demonstrate how to use theuse_oriented_boxesparameter with both axis-aligned and oriented bounding boxes.
Excellent initiative on adding OBB support to confusion matrix evaluation! This enhancement addresses a critical gap for oriented object detection benchmarking. The implementation approach is solid and follows good software engineering practices.
Technical Assessment:
-
Architecture: The
use_oriented_boxesparameter design is clean and maintains backward compatibility. The conditional IoU logic betweenbox_iou_batchandoriented_box_iou_batchis well-structured. -
Implementation Strengths:
- Comprehensive parameter propagation through
from_detections,from_tensors, andevaluate_detection_batch - Dedicated test suite for OBB scenarios
- Clear documentation updates with practical examples
- Non-breaking change design
- Comprehensive parameter propagation through
-
Addressing Review Feedback:
- @soumik12345's suggestion to add OBB support to
ConfusionMatrix.benchmarkis valid and should be implemented - The failing test case indicates potential issues with the current oriented IoU implementation
- @soumik12345's suggestion to add OBB support to
Technical Recommendations:
-
Test Debugging: Investigate the failing test case by:
- Verifying
oriented_box_iou_batchoutput for your test geometries - Adding debug prints to compare expected vs actual IoU values
- Ensuring OBB format consistency (center, width, height, angle representation)
- Verifying
-
Benchmark Method: Add the
use_oriented_boxesparameter to thebenchmarkclassmethod for complete API consistency -
Edge Cases: Consider testing scenarios with:
- Various rotation angles (0°, 45°, 90°, etc.)
- Degenerate cases (zero area boxes)
- High-overlap oriented boxes at different angles
This enhancement will significantly benefit the computer vision community working with oriented detection tasks. The approach aligns well with modern evaluation practices.
Best regards, Gabriel