Add Oriented Bounding Box (OBB) support for rotated object detection#921
Open
farukalamai wants to merge 15 commits intoroboflow:developfrom
Open
Add Oriented Bounding Box (OBB) support for rotated object detection#921farukalamai wants to merge 15 commits intoroboflow:developfrom
farukalamai wants to merge 15 commits intoroboflow:developfrom
Conversation
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (80%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #921 +/- ##
=======================================
+ Coverage 79% 80% +1%
=======================================
Files 97 99 +2
Lines 7793 8061 +268
=======================================
+ Hits 6148 6410 +262
- Misses 1645 1651 +6 🚀 New features to boost your workflow:
|
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.
What does this PR do?
Adds OBB (Oriented Bounding Box) support to RF-DETR, enabling rotated object detection with
[cx, cy, w, h, angle]box format. This includes rotated box math utilities, DOTA v1.0 dataset loader, angle prediction head, Gaussian-based matching/loss functions, and oriented postprocessing.When
oriented=Trueis set inModelConfig, the model predicts a 5th dimension (rotation angle in radians) per box, uses KLD loss for regression, GWD cost for Hungarian matching, and outputs rotated corner points.Related Issue(s): Fixes #56
Type of Change
Testing
Test details:
75 new tests covering all OBB components:
test_rotated_box_ops.py(34 tests) — angle normalization, box conversions, roundtrips, GWD/KLD/ProbIoU losses, gradient flow, edge cases (zero-size boxes, large boxes)test_dota_detection.py(21 tests) — annotation parsing, dataset loading, filtering, normalization, empty/missing filestest_obb_head.py(8 tests) — detection head output shapes, angle range, gradient flowtest_obb_matcher_criterion.py(6 tests) — oriented matching, KLD loss computationtest_obb_postprocess.py(5 tests) — output keys, shapes, scaling, batch supporttest_obb_export.py(2 tests) — ONNX export produces 5D output with valid anglestest_obb_integration.py(5 tests) — config flag, namespace forwarding, dataset_file acceptanceAll existing tests pass unchanged.
Checklist
Additional Context
Key design decisions:
angle_embedMLP rather than extendingbbox_embedto 5D — keeps spatial box prediction unchangedbox_iouwhen orientedoriented: bool = Falseon ModelConfig — zero impact on existing non-oriented modelsFiles changed
New files:
src/rfdetr/utilities/rotated_box_ops.py— box conversions, Gaussian encoding, GWD/KLD/ProbIoUsrc/rfdetr/datasets/dota_detection.py— DOTA v1.0 dataset loader with annotation parsertests/— 7 new test files (75 tests)Modified files:
src/rfdetr/config.py— addedorientedflag and"dota"dataset optionsrc/rfdetr/_namespace.py— forwardorientedto namespacesrc/rfdetr/models/_types.py— addedorientedtoBuilderArgsprotocolsrc/rfdetr/models/heads/detection.py— addedangle_embedMLP when orientedsrc/rfdetr/models/lwdetr.py— angle prediction in forward pass, zero-init, builder wiringsrc/rfdetr/models/matcher.py— GWD pairwise cost for oriented matchingsrc/rfdetr/models/criterion.py— KLD loss for oriented boxes, ProbIoU for ia_bce_losssrc/rfdetr/models/postprocess.py— oriented output withboxes_obbandcornerssrc/rfdetr/datasets/__init__.py— registered DOTA dataset builder