Format I/O
Panlabel provides I/O modules for reading and writing various annotation formats. All formats convert through the Intermediate Representation, ensuring consistent behavior.Supported Formats
Each format has a dedicated module inpanlabel::ir with read_* and write_* functions:
| Format | Module | Read Function | Write Function |
|---|---|---|---|
| IR JSON | io_json | read_ir_json | write_ir_json |
| COCO | io_coco_json | read_coco_json | write_coco_json |
| YOLO | io_yolo | read_yolo_dir | write_yolo_dir |
| Pascal VOC | io_voc_xml | read_voc_dir | write_voc_dir |
| CVAT | io_cvat_xml | read_cvat_xml | write_cvat_xml |
| Label Studio | io_label_studio_json | read_label_studio_json | write_label_studio_json |
| TensorFlow Object Detection | io_tfod_csv | read_tfod_csv | write_tfod_csv |
Common Patterns
All I/O functions follow consistent patterns:Reading
Writing
IR JSON
Panlabel’s native JSON format - lossless representation of the IR.- Lossless (preserves all IR information)
- Human-readable JSON
- Single file
- Direct serialization of IR types
COCO JSON
Microsoft COCO object detection format.- Single JSON file
- Bounding boxes in
[x, y, width, height]format - Preserves most metadata and attributes
- Standard format for COCO dataset
- COCO uses
[x, y, width, height]where(x, y)is top-left - Panlabel IR uses
(xmin, ymin, xmax, ymax) - Conversion:
xmax = x + width,ymax = y + height
YOLO
Ultralytics YOLO directory-based format.- Directory-based:
images/andlabels/subdirectories - Class mapping from
data.yamlorclasses.txt - Normalized coordinates:
<class_idx> <cx> <cy> <w> <h> - One
.txtfile per image (empty files for images without annotations)
- YOLO uses normalized center-based:
(cx, cy, w, h)in[0, 1] - Panlabel IR uses pixel XYXY:
(xmin, ymin, xmax, ymax) - Conversion:
- To YOLO: normalize by image dimensions, convert to center format
- From YOLO: denormalize by image dimensions, convert to XYXY
Pascal VOC XML
Pascal VOC directory-based XML format.- Directory-based:
Annotations/(XML) andJPEGImages/(images) - One XML file per image
- Preserves attributes:
pose,truncated,difficult,occluded - Pixel coordinates in
<bndbox>elements
CVAT XML
CVAT for Images XML export format.- Single XML file or directory with
annotations.xml - Preserves attributes:
occluded,z_order, custom attributes - Pixel coordinates in
xtl,ytl,xbr,ybrattributes
Label Studio JSON
Label Studio task export format.- JSON array of tasks
- Percentage-based coordinates (0-100)
- Preserves rotation with
ls_rotation_degattribute - Image references stored in
data.image
TensorFlow Object Detection CSV
TensorFlow Object Detection CSV format.- Single CSV file
- Pixel coordinates:
xmin,ymin,xmax,ymax - One row per annotation
- Images without annotations are not represented
Error Handling
All I/O functions returnResult<T, PanlabelError> with detailed error context:
Complete Example
Convert between multiple formats:Next Steps
- Understand the Intermediate Representation types
- Use Validation to check dataset quality
- Analyze format compatibility with Conversion reporting