fix: populate class_name in DetectionDataset annotations#2156
Merged
Borda merged 3 commits intoroboflow:developfrom Feb 25, 2026
Merged
fix: populate class_name in DetectionDataset annotations#2156Borda merged 3 commits intoroboflow:developfrom
Borda merged 3 commits intoroboflow:developfrom
Conversation
DetectionDataset.__init__ now maps class_id to class names using CLASS_NAME_DATA_FIELD so that LabelAnnotator displays human-readable labels instead of raw integer IDs. Closes roboflow#1772
0e8ac54 to
9314487
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2156 +/- ##
=======================================
Coverage 74% 74%
=======================================
Files 62 62
Lines 7486 7492 +6
=======================================
+ Hits 5547 5554 +7
+ Misses 1939 1938 -1 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where DetectionDataset displays raw class IDs (e.g., 0, 1) instead of human-readable class names (e.g., "dog", "cat") when using LabelAnnotator. The fix populates the class_name data field centrally in DetectionDataset.__init__ by mapping class_id values to class names from the dataset's classes list.
Changes:
- Added logic to populate
CLASS_NAME_DATA_FIELDinDetectionDataset.__init__for all annotations - Added comprehensive test coverage including edge cases (empty annotations, merge operations, YOLO integration)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/supervision/dataset/core.py | Added import of CLASS_NAME_DATA_FIELD and logic in __init__ to populate class_name in annotation data by indexing the classes list with class_id values |
| tests/dataset/test_core.py | Added TestClassNamePopulation test class with 5 test cases covering initialization, empty annotations, empty classes, merge operations, and YOLO format integration |
Merged
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.
DetectionDataset.init now maps class_id to class names using CLASS_NAME_DATA_FIELD so that LabelAnnotator displays human-readable labels instead of raw integer IDs.
Closes #1772
Before submitting
Description
DetectionDataset.__init__now populatesCLASS_NAME_DATA_FIELDin each annotation'sdatadict by mappingclass_idto the dataset'sclasseslist. This is done centrally in the constructor so all format loaders (from_yolo,from_coco,from_pascal_voc) benefit without individual changes.Type of Change
Motivation and Context
When loading a dataset via
DetectionDataset.from_yolo(...)and annotating withLabelAnnotator, labels showed raw integer class IDs (e.g.0,1) instead of human-readable class names (e.g.dog,person). This is because theclass_namedata field was never populated on dataset-loadedDetections, unlikeDetections.from_inference()which does set it.Closes #1772
Changes Made
CLASS_NAME_DATA_FIELDimport tosrc/supervision/dataset/core.pyDetectionDataset.__init__to populateclass_namefromclassesandclass_idtests/dataset/test_core.pycovering init, empty detections, empty classes, merge, and YOLO integrationTesting
Google Colab
Before fix: https://colab.research.google.com/drive/1ycOTk-zxUnjD_ZHcD8LBDlUVc9jij2Iu?usp=sharing
After fix: https://colab.research.google.com/drive/1kkz0YbwJv7X-9o9AVWu6v601sR4Bc5q9?usp=sharing
Screenshots/Videos
Additional Notes
No changes to individual format loaders or annotator logic were needed.