RF-DETR supports training on datasets in two popular formats: COCO and YOLO. The format is automatically detected based on your dataset’s directory structure — simply pass your dataset directory to theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/roboflow/rf-detr/llms.txt
Use this file to discover all available pages before exploring further.
train() method.
Automatic format detection
When you callmodel.train(dataset_dir="<path>"), RF-DETR checks the following:
- COCO format: Looks for
train/_annotations.coco.json - YOLO format: Looks for
data.yaml(ordata.yml) andtrain/images/directory
Format structures
- COCO format
- YOLO format
COCO (Common Objects in Context) format uses JSON files to store annotations in a structured format with images, categories, and annotations.
The
Directory structure
Annotation file structure
Each_annotations.coco.json file contains:| Field | Description |
|---|---|
images | List of image metadata including id, file_name, width, height |
categories | List of object categories with id and name |
annotations | List of object annotations linking images to categories |
bbox | Bounding box in [x, y, width, height] format (top-left corner) |
area | Area of the bounding box |
iscrowd | 0 for individual objects, 1 for crowd regions |
Segmentation annotations
For training segmentation models, your COCO annotations must include asegmentation key with polygon coordinates:segmentation field contains a list of polygons, where each polygon is a flat list of coordinates: [x1, y1, x2, y2, x3, y3, ...].Converting between formats
Use the supervision library to convert between COCO and YOLO formats:- YOLO to COCO
- COCO to YOLO
Which format should I use?
Both formats work equally well with RF-DETR. Choose based on your workflow:| Consideration | COCO | YOLO |
|---|---|---|
| Annotation storage | Single JSON file per split | One text file per image |
| Human readability | JSON structure, verbose | Simple text, compact |
| Other framework compatibility | DETR family, MMDetection | Ultralytics YOLO |
| Segmentation support | Full polygon support | Full polygon support |
| Editing annotations | Requires JSON parsing | Simple text editing |
Troubleshooting
Format detection fails
If you see an error likeCould not detect dataset format in /path/to/dataset, check:
For COCO format:
train/_annotations.coco.jsonexists- The JSON file is valid
data.yamlordata.ymlexists at the roottrain/images/directory exists with images
Empty annotations
COCO format: Include the image in theimages array but don’t add any annotations for it.
YOLO format: Create an empty .txt file (0 bytes) for the image, or omit the label file entirely.
Class ID mismatch
COCO format: Category IDs in annotations must match IDs defined in thecategories array.
YOLO format: Class IDs in label files must be valid indices (0 to nc-1) based on the names list in data.yaml.