yolo-to-json: Convert YOLO to JSON Format¶
The yolo-to-json command converts YOLO format annotations to a more readable and portable JSON format. This can be useful for data examination, sharing, or as an intermediate format for further processing.
Usage¶
Parameters¶
INPUT_DIR: Directory containing YOLO annotation text filesNAMES_FILE: File containing class names, one per lineWIDTH: Image width (for scaling normalized YOLO coordinates)HEIGHT: Image height (for scaling normalized YOLO coordinates)OUTPUT_FILE: Path to save the output JSON file--round: (Optional) Round the scaled coordinates to the nearest whole number
Output Format¶
The JSON output follows this structure:
{
"/absolute/path/to/annotation1.txt": [
{
"concept": "class_name",
"x": 100,
"y": 200,
"width": 50,
"height": 40
},
...
],
"/absolute/path/to/annotation2.txt": [
...
]
}
How It Works¶
- The command reads all YOLO annotation files (
.txt) in the input directory - For each annotation, it converts:
- Class indices to human-readable class names using the provided names file
- Normalized coordinates to absolute pixel coordinates using the provided dimensions
- Center-based coordinates (YOLO) to top-left coordinates (traditional)
- All annotations are compiled into a single JSON file
Coordinate Precision
Use the --round flag when you need integer coordinates (e.g., for displaying in pixel-based applications).
Omit it when you need to preserve the exact floating-point precision (e.g., for mathematical analysis).
Examples¶
Basic conversion with integer coordinates:
Preserving floating point precision: