--from explicitly. This makes commands more concise and reduces errors from format mismatches.
Using Auto-Detection
Use--from auto with the convert command:
--from (defaults to auto):
stats, diff, and sample commands also support auto-detection:
Detection Heuristics
Panlabel uses a multi-layered approach to detect formats:File Type Detection
First, Panlabel examines the file extension:| Extension | Initial Guess | Next Step |
|---|---|---|
.json | JSON format | Inspect content to distinguish COCO, Label Studio, or IR JSON |
.xml | XML format | Inspect content to distinguish CVAT or VOC |
.csv | TFOD format | Directly recognized as TensorFlow Object Detection format |
| Directory | Directory-based | Check for YOLO, VOC, or CVAT directory layouts |
JSON Format Detection
For JSON files, Panlabel inspects the structure (fromdetect_json_format in lib.rs:987-1092):
Array-Root JSON
If the JSON root is an array:Label Studio uses an array of task objects, each with a
data object containing an image field.Object-Root JSON
If the JSON root is an object, Panlabel inspects theannotations[0].bbox structure:
COCO Format: bbox is an array of 4 numbers [x, y, width, height]:
bbox is an object with min/max or xmin/ymin/xmax/ymax fields:
XML Format Detection
For XML files, Panlabel inspects the root element (fromdetect_xml_format in lib.rs:1094-1119):
| Root Element | Detected Format | Notes |
|---|---|---|
<annotations> | CVAT XML | CVAT for images export |
<annotation> | Error | Single VOC file; use directory path instead |
| Other | Error | Unknown XML format |
CVAT XML Example
VOC XML Single File
--from voc with the VOC dataset directory.
Pascal VOC uses a directory layout with multiple XML files. Auto-detection works for VOC directories, not individual XML files.
Directory Layout Detection
For directories, Panlabel checks for specific structures (fromdetect_dir_format in lib.rs:882-941):
YOLO Directory
Recognized if any of these conditions are met:- Directory contains a
labels/subdirectory with.txtfiles - Directory is named
labels/(case-insensitive) and contains.txtfiles
labels/:
VOC Directory
Recognized if any of these conditions are met:- Directory contains
Annotations/(with.xmlfiles) andJPEGImages/subdirectories - Directory is named
Annotations/(case-insensitive), contains.xmlfiles, and has siblingJPEGImages/directory
Annotations/:
CVAT Directory
Recognized if:- Directory contains
annotations.xmlat root
Ambiguous Cases
If a directory matches multiple formats, detection fails with a clear error:- YOLO + VOC: Directory has both
labels/with.txtfiles andAnnotations/with.xmlfiles - YOLO + CVAT: Directory has
labels/with.txtfiles andannotations.xml - VOC + CVAT: Directory has
Annotations/with.xmlfiles andannotations.xml
When to Use Explicit Format
Empty Datasets
Auto-detection fails for empty datasets:Missing Bounding Boxes
If the first annotation lacks abbox field:
--from explicitly.
Ambiguous Directory Layouts
When a directory matches multiple formats:Custom or Non-Standard Formats
If your dataset uses a non-standard structure or extension:Single VOC XML Files
VOC XML files are not auto-detected individually:Debugging Detection Issues
If auto-detection fails unexpectedly:- Check the error message - Panlabel provides detailed reasons for detection failures
- Verify file structure - Ensure your dataset follows the expected layout for your format
- Inspect sample data - Check that the first annotation has a
bboxfield (for JSON formats) - Use explicit format - When in doubt, specify
--fromexplicitly
Common Error Messages
| Error Message | Cause | Solution |
|---|---|---|
unrecognized file extension | Unknown file type | Use --from to specify format |
empty 'annotations' array | No annotations to inspect | Use --from or add annotations |
first annotation has no 'bbox' field | Invalid annotation structure | Fix annotation or use --from |
directory matches both YOLO and VOC layouts | Ambiguous directory | Use --from to specify format |
missing or invalid 'annotations' array | Malformed JSON | Fix JSON structure or use --from |
array-root JSON not recognized | Unknown array-root format | Check if itβs valid Label Studio format |
Stats Command Fallback
Thestats command has special fallback behavior for JSON files:
.json file, stats falls back to reading as ir-json. This is convenient for IR JSON files that may have non-standard structures during development.
This fallback only applies to
stats. The convert and validate commands will still fail if detection fails.Best Practices
Use Auto-Detection for Interactive Work
Auto-detection makes exploratory data analysis faster:Use Explicit Format in Scripts
For production scripts, specify formats explicitly for:- Predictability
- Better error messages
- Documentation clarity
Document Expected Formats
In documentation and READMEs, always specify formats explicitly:Related Topics
- Format Conversion - Converting between formats
- Supported Formats - Detailed format specifications
convertCommand - Full conversion documentation