-
Notifications
You must be signed in to change notification settings - Fork 597
Adding support for YOLO formats #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
- Introduce `ConvertYolo` for converting YOLO detections to RF-DETR's target format. - Add `YoloDetection` class for handling YOLO-format datasets with optional mask support.
…ow` logic, reduce redundancy by reusing shared functionality.
…Roboflow dataset structure handling - Introduce `build_roboflow_from_yolo` for handling YOLO-format datasets. - Refactor `build_roboflow_from_coco` to streamline attribute handling and adjust Roboflow's dataset structure mapping.
- Introduce `detect_roboflow_format` to auto-detect COCO or YOLO format. - Refactor `build_roboflow` to delegate to the appropriate builder based on detected format. - Update `build_dataset` to use the new unified `build_roboflow` function.
- Introduce `YoloCoco` as a minimal wrapper for YOLO datasets to enable COCO-style evaluation. - Update `YoloDetection` to initialize the `YoloCoco` wrapper for seamless integration with COCO evaluators. - Modify dataset initialization logic to support both COCO and YOLO formats.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #569 +/- ##
=======================================
- Coverage 21% 20% -0%
=======================================
Files 45 46 +1
Lines 5960 6196 +236
=======================================
+ Hits 1225 1261 +36
- Misses 4735 4935 +200 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds comprehensive support for YOLO format datasets to RF-DETR, complementing the existing COCO format support. The implementation includes automatic format detection, unified dataset loading, and improved class name extraction that works with both formats.
Changes:
- Added YOLO dataset loader with supervision integration and COCO API compatibility wrapper
- Implemented automatic format detection for Roboflow datasets to distinguish between COCO and YOLO formats
- Refactored class name extraction into a unified method supporting both COCO JSON and YOLO YAML formats
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| rfdetr/datasets/yolo.py | New file implementing YOLO dataset support with ConvertYolo, YoloCoco wrapper, YoloDetection dataset class, and builder function |
| rfdetr/datasets/init.py | Added format detection logic and dispatcher function to route to appropriate builder based on detected format |
| rfdetr/datasets/coco.py | Renamed build_roboflow to build_roboflow_from_coco, replaced try-except blocks with getattr for cleaner argument handling, removed empty docstring |
| rfdetr/detr.py | Added _load_classes static method to load class names from either COCO or YOLO datasets, with support for both JSON and YAML formats |
Comments suppressed due to low confidence (1)
rfdetr/datasets/coco.py:249
- The
buildfunction for COCO still uses a try-except block forsquare_resize_div_64(lines 246-249), while the refactoredbuild_roboflow_from_cocofunction usesgetattrfor the same purpose (line 289). For consistency with the refactoring approach described in the PR, consider updating this try-except block to usegetattras well.
try:
square_resize_div_64 = args.square_resize_div_64
except:
square_resize_div_64 = False
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def getCatIds(self, catNms=None, supNms=None, catIds=None): | ||
| """Get category IDs that satisfy given filter conditions.""" | ||
| if catNms is None: | ||
| catNms = [] | ||
| if supNms is None: | ||
| supNms = [] | ||
| if catIds is None: | ||
| catIds = [] | ||
|
|
||
| cats = self.dataset["categories"] | ||
|
|
||
| if len(catNms) > 0: | ||
| cats = [cat for cat in cats if cat["name"] in catNms] | ||
| if len(catIds) > 0: | ||
| cats = [cat for cat in cats if cat["id"] in catIds] | ||
|
|
||
| return [cat["id"] for cat in cats] |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getCatIds method accepts a supNms parameter (line 242) but never uses it in the filtering logic. If supercategory name filtering is not needed for YOLO datasets (which always use "none" as supercategory), consider adding a comment explaining this, or implement the filtering for API completeness.
| # any YAML file starting with data e.g. data.yaml, dataset.yaml | ||
| yaml_data_files = [yp for yp in yaml_paths if os.path.basename(yp).startswith("data")] |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 138 describes filtering for YAML files starting with "data" but the actual examples given (e.g., "data.yaml, dataset.yaml") show that "dataset.yaml" doesn't start with "data". This creates a mismatch between the comment and the code behavior. The code correctly filters for files starting with "data", but the comment and error message on line 156 should be updated to reflect this accurately.
- Add `_MockSvDataset` for testing `YoloCoco` functionality. - Extend docstrings with examples and argument details for key `YoloCoco` methods.
…into data/load-yolo
Co-authored-by: Copilot <[email protected]>
…n length check and simplifying iteration.
This pull request adds robust support for both COCO and YOLO Roboflow datasets by auto-detecting the dataset format and delegating to the appropriate loader. It introduces utility functions for format detection, improves class name extraction for both formats, and simplifies argument handling in dataset builders.
Roboflow Dataset Format Detection and Loading:
detect_roboflow_formatand a newbuild_roboflowfunction inrfdetr/datasets/__init__.pyto automatically detect whether a Roboflow dataset is in COCO or YOLO format and call the correct builder (build_roboflow_from_cocoorbuild_roboflow_from_yolo).YoloDetectionclass for type checking.Class Name Extraction Improvements:
rfdetr/detr.pyto add a_load_classesstatic method that loads class names from either COCO or YOLO-style datasets (supporting both JSON and YAML formats), with error handling for ambiguous or missing files.Builder and Argument Handling Simplification:
build_roboflow_from_cocofunction, and replaced repeated try/except blocks withgetattrfor cleaner argument extraction.Minor Code Quality Improvements: