Skip to content

Add oriented bounding box support for DOTAv1 datasets#842

Draft
janerikvw wants to merge 2 commits intoroboflow:developfrom
janerikvw:claude/coco-to-dotav1-conversion-TvF3i
Draft

Add oriented bounding box support for DOTAv1 datasets#842
janerikvw wants to merge 2 commits intoroboflow:developfrom
janerikvw:claude/coco-to-dotav1-conversion-TvF3i

Conversation

@janerikvw
Copy link

Summary

This PR adds comprehensive support for oriented bounding boxes (OBB) in RF-DETR, including a new DOTAv1 dataset loader, multi-dataset configuration system, and OBB-specific operations and loss functions.

Key Changes

New Dataset Support

  • DOTAv1 Dataset Loader (src/rfdetr/datasets/dota.py): Implements DotaDetection class to load DOTAv1 format datasets with 8-point corner annotations. Supports both oriented and axis-aligned bounding box modes.
  • Multi-Dataset Configuration (src/rfdetr/datasets/multi.py): Adds YAML-based multi-dataset configuration system with ClassMappingDataset wrapper for class remapping and OBB padding across heterogeneous datasets.

OBB Operations

  • Box Operations (src/rfdetr/utilities/box_ops.py):
    • corners_to_obb(): Converts 4 corner points to normalized OBB representation (cx, cy, w, h, angle)
    • obb_to_corners(): Inverse conversion from OBB to corner points
    • circular_angle_loss(): Circular loss for angle predictions accounting for 180° symmetry

Model Updates

  • LWDETR (src/rfdetr/models/lwdetr.py): Added oriented parameter to predict 5-dim boxes (cx, cy, w, h, angle) when enabled
  • Criterion (src/rfdetr/models/criterion.py): Added oriented flag and loss_angle_coef for angle loss weighting
  • PostProcess (src/rfdetr/models/postprocess.py): Updated to handle 5-dim oriented box outputs
  • Matcher (src/rfdetr/models/matcher.py): Updated to handle oriented boxes in cost computation

Configuration & Training

  • Config (src/rfdetr/config.py):
    • Added oriented field to ModelConfig
    • Added loss_angle_coef to TrainConfig
    • Extended dataset_file to support "dota" and "multi" formats
    • New DatasetEntry and MultiDatasetConfig classes for multi-dataset YAML configs
  • Transforms (src/rfdetr/datasets/transforms.py): Enhanced Normalize to convert OBB corners to normalized angle representation; updated geometric transforms to handle corner points as keypoints
  • Data Module (src/rfdetr/training/module_data.py): Added weighted sampling support for multi-dataset training
  • Namespace (src/rfdetr/_namespace.py): Propagated oriented flag through build pipeline

Testing

  • DOTAv1 Tests (tests/datasets/test_dota.py): Comprehensive tests for dataset loading, oriented/non-oriented modes, class mapping, and edge cases
  • Multi-Dataset Tests (tests/datasets/test_multi.py): Tests for YAML config parsing, class mapping, and OBB padding
  • OBB Operations Tests (tests/utilities/test_obb_box_ops.py): Tests for corner↔OBB conversions, roundtrip consistency, and circular angle loss
  • Config Tests (tests/test_obb_config.py): Tests for new configuration fields

Implementation Details

  • OBB angles are normalized to [0, π) to handle 180° symmetry of rectangles
  • Corner points are treated as keypoints during augmentation to preserve orientation
  • Multi-dataset support includes per-dataset class mapping and augmentation config overrides
  • Weighted sampling enables balanced training across datasets with different sizes

https://claude.ai/code/session_01DC76DdnusAVRPbF1NXfska

…multi-dataset YAML config

Add 5-parameter oriented bounding box prediction (cx, cy, w, h, angle) to RF-DETR,
enabling rotated object detection for aerial/satellite imagery. This includes:

- Model: bbox_embed outputs 5 params when oriented=True, with sigmoid angle in [0,1)
- Loss: circular-aware L1 angle loss, spatial-only GIoU, spatial-only Hungarian matching
- PostProcess: angle output in radians [0, pi) with corner conversion utilities
- DOTAv1 dataset loader: parses corner-point annotations, converts to OBB representation
- Multi-dataset YAML config: combine datasets with per-dataset weights, class mapping,
  format (coco/yolo/dota), oriented flag, and augmentation overrides
- Keypoint-based OBB augmentation: corners tracked through geometric transforms
- Box ops: corners_to_obb, obb_to_corners, circular_angle_loss utilities
- 34 new tests covering all components

https://claude.ai/code/session_01DC76DdnusAVRPbF1NXfska
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 59.68170% with 152 lines in your changes missing coverage. Please review.
✅ Project coverage is 74%. Comparing base (3cd6898) to head (8670cd6).
⚠️ Report is 4 commits behind head on develop.

❌ Your patch check has failed because the patch coverage (60%) is below the target coverage (95%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (74%) 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   #842    +/-   ##
=======================================
- Coverage       75%    74%    -1%     
=======================================
  Files           92     94     +2     
  Lines         7148   7509   +361     
=======================================
+ Hits          5383   5594   +211     
- Misses        1765   1915   +150     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda
Copy link
Member

Borda commented Mar 20, 2026

Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@janerikvw ^^ 🙏

@Borda Borda added enhancement New feature or request waiting on author labels Mar 20, 2026
@Borda Borda marked this pull request as draft March 22, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants