module documentation

Utilities for working with datasets in YOLO format.

Copyright 2017-2025, Voxel51, Inc.

Class YOLOAnnotationWriter Class for writing annotations in YOLO-style TXT format.
Class YOLOv4DatasetExporter Exporter that writes YOLOv4 datasets to disk.
Class YOLOv4DatasetImporter Importer for YOLOv4 datasets stored on disk.
Class YOLOv5DatasetExporter Exporter that writes YOLOv5 datasets to disk.
Class YOLOv5DatasetImporter Importer for YOLOv5 datasets stored on disk.
Function add_yolo_labels Adds the given YOLO-formatted labels to the collection.
Function load_yolo_annotations Loads the YOLO-style annotations from the given TXT file.
Variable logger Undocumented
Function _get_yolo_v5_labels_path Undocumented
Function _make_yolo_row Undocumented
Function _make_yolo_v5_path Undocumented
Function _parse_yolo_classes Undocumented
Function _parse_yolo_row Undocumented
Function _parse_yolo_v5_path Undocumented
Function _read_file_lines Undocumented
Function _read_yaml_file Undocumented
Function _to_classes Undocumented
Function _to_labels_map_rev Undocumented
Function _write_file_lines Undocumented
Function _write_yaml_file Undocumented
def add_yolo_labels(sample_collection, label_field, labels_path, classes, label_type='detections', include_missing=False): (source)

Adds the given YOLO-formatted labels to the collection.

Each YOLO txt file should be a space-delimited file whose rows define objects in one of the following formats:

# Detections
<target> <x-center> <y-center> <width> <height>
<target> <x-center> <y-center> <width> <height> <confidence>

# Polylines
<target> <x1> <y1> <x2> <y2> <x3> <y3> ...

where target is the zero-based integer index of the object class label from classes and the bounding box coordinates are expressed as relative coordinates in [0, 1] x [0, 1].

Parameters
sample_collectiona fiftyone.core.collections.SampleCollection
label_fieldthe label field in which to store the labels. The field will be created if necessary
labels_path

the YOLO-formatted labels to load. This can be any of the following:

  • a dict mapping either image filenames or absolute filepaths to YOLO TXT filepaths. The image filenames/filepaths should match those in sample_collection, in any order
  • a list of YOLO TXT filepaths corresponding 1-1 to the samples in sample_collection
  • a directory containing YOLO TXT files whose filenames (less extension) correspond to image filenames in sample_collection, in any order
classesthe list of class label strings
label_type:"detections"the label format to load. The supported values are ("detections", "polylines")
include_missing:Falsewhether to insert empty labels for any samples in the input collection whose label_field is None after import
def load_yolo_annotations(txt_path, classes, label_type='detections'): (source)

Loads the YOLO-style annotations from the given TXT file.

The txt file should be a space-delimited file where each row corresponds to an object in one the following formats:

# Detections
<target> <x-center> <y-center> <width> <height>
<target> <x-center> <y-center> <width> <height> <confidence>

# Polylines
<target> <x1> <y1> <x2> <y2> <x3> <y3> ...

where target is the zero-based integer index of the object class label from classes and all coordinates are expressed as relative values in [0, 1] x [0, 1].

Parameters
txt_paththe path to the annotations TXT file
classesthe list of class label strings
label_type:"detections"the label format to load. The supported values are ("detections", "polylines")
Returns
a fiftyone.core.labels.Detections or fiftyone.core.labels.Polylines

Undocumented

def _get_yolo_v5_labels_path(image_path): (source)

Undocumented

def _make_yolo_row(label, target, confidence=None): (source)

Undocumented

def _make_yolo_v5_path(filepath, yaml_path): (source)

Undocumented

def _parse_yolo_classes(classes): (source)

Undocumented

def _parse_yolo_row(row, classes, label_type): (source)

Undocumented

def _parse_yolo_v5_path(filepath, yaml_path): (source)

Undocumented

def _read_file_lines(path): (source)

Undocumented

def _read_yaml_file(path): (source)

Undocumented

def _to_classes(labels_map_rev): (source)

Undocumented

def _to_labels_map_rev(classes): (source)

Undocumented

def _write_file_lines(lines, outpath): (source)

Undocumented

def _write_yaml_file(d, path, **kwargs): (source)

Undocumented