module documentation

TensorFlow utilities.

Copyright 2017-2025, Voxel51, Inc.

Class TFExampleGenerator Base class for sample writers that emit tf.train.Example protos.
Class TFImageClassificationDatasetExporter Exporter that writes an image classification dataset to disk as TFRecords.
Class TFImageClassificationDatasetImporter Importer for TF image classification datasets stored on disk.
Class TFImageClassificationExampleGenerator Class for generating tf.train.Example protos for samples in TF image classification format.
Class TFImageClassificationSampleParser Parser for image classification samples stored as TFRecords.
Class TFObjectDetectionDatasetExporter Exporter that writes an object detection dataset to disk as TFRecords in the TF Object Detection API format.
Class TFObjectDetectionDatasetImporter Importer for TF detection datasets stored on disk.
Class TFObjectDetectionExampleGenerator Class for generating tf.train.Example protos for samples in TF Object Detection API format.
Class TFObjectDetectionSampleParser Parser for samples in TF Object Detection API format.
Class TFRecordSampleParser Base class for sample parsers that ingest tf.train.Example protos containing labeled images.
Class TFRecordsDatasetExporter Base class for fiftyone.utils.data.exporters.LabeledImageDatasetExporter instances that export labeled images as TFRecords datasets on disk.
Class TFRecordsLabeledImageDatasetImporter Base class for fiftyone.utils.data.importers.LabeledImageDatasetImporter instances that import tf.train.Example protos containing labeled images.
Class TFRecordsWriter Class for writing TFRecords to disk.
Function from_image_classification_dir_tree Creates a tf.data.Dataset for the given image classification dataset directory tree.
Function from_image_paths_and_labels Creates a tf.data.Dataset for an image classification dataset stored as a list of image paths and labels.
Function from_images Creates a tf.data.Dataset for the given list of images.
Function from_images_dir Creates a tf.data.Dataset for the given directory of images.
Function from_images_patt Creates a tf.data.Dataset for the given glob pattern of images.
Function from_tf_records Creates a tf.data.Dataset for the TFRecords at the given path(s).
Function write_tf_records Writes the given tf.train.Example protos to disk as TFRecords.
Variable logger Undocumented
Function _bytes_feature Undocumented
Function _bytes_list_feature Undocumented
Function _float_feature Undocumented
Function _float_list_feature Undocumented
Function _get_classes_for_detections Undocumented
Function _int64_feature Undocumented
Function _int64_list_feature Undocumented
Function _parse_image_tf Undocumented
Function _to_labels_map_rev Undocumented
def from_image_classification_dir_tree(dataset_dir, force_rgb=False, num_parallel_calls=None): (source)

Creates a tf.data.Dataset for the given image classification dataset directory tree.

The directory should have the following format:

<dataset_dir>/
    <classA>/
        <image1>.<ext>
        <image2>.<ext>
        ...
    <classB>/
        <image1>.<ext>
        <image2>.<ext>
        ...
Parameters
dataset_dirthe dataset directory
force_rgb:Falsewhether to force convert all images to RGB
num_parallel_calls:Nonethe number of samples to read asynchronously in parallel. See https://www.tensorflow.org/api_docs/python/tf/data/Dataset#map for details
Returns
a tuple of
  • dataset: a tf.data.Dataset` that emits ``(img, label) pairs
  • classes: a list of class label strings
def from_image_paths_and_labels(image_paths, labels, force_rgb=False, num_parallel_calls=None): (source)

Creates a tf.data.Dataset for an image classification dataset stored as a list of image paths and labels.

Parameters
image_pathsan iterable of image paths
labelsan iterable of labels
force_rgb:Falsewhether to force convert all images to RGB
num_parallel_calls:Nonethe number of samples to read asynchronously in parallel. See https://www.tensorflow.org/api_docs/python/tf/data/Dataset#map for details
Returns
a tf.data.Dataset that emits (img, label) pairs
def from_images(image_paths, force_rgb=False, num_parallel_calls=None): (source)

Creates a tf.data.Dataset for the given list of images.

Parameters
image_pathsan iterable of image paths
force_rgb:Falsewhether to force convert all images to RGB
num_parallel_calls:Nonethe number of samples to read asynchronously in parallel. See https://www.tensorflow.org/api_docs/python/tf/data/Dataset#map for details
Returns
a tf.data.Dataset that emits decoded images
def from_images_dir(images_dir, recursive=True, force_rgb=False, num_parallel_calls=None): (source)

Creates a tf.data.Dataset for the given directory of images.

Parameters
images_dira directory of images
recursive:Truewhether to recursively traverse subdirectories
force_rgb:Falsewhether to force convert all images to RGB
num_parallel_calls:Nonethe number of samples to read asynchronously in parallel. See https://www.tensorflow.org/api_docs/python/tf/data/Dataset#map for details
Returns
a tf.data.Dataset that emits decoded images
def from_images_patt(images_patt, force_rgb=False, num_parallel_calls=None): (source)

Creates a tf.data.Dataset for the given glob pattern of images.

Parameters
images_patta glob pattern of images like /path/to/images/*.jpg
force_rgb:Falsewhether to force convert all images to RGB
num_parallel_calls:Nonethe number of samples to read asynchronously in parallel. See https://www.tensorflow.org/api_docs/python/tf/data/Dataset#map for details
Returns
a tf.data.Dataset that emits decoded images
def from_tf_records(tf_records_patt, buffer_size=None, num_parallel_reads=None): (source)

Creates a tf.data.Dataset for the TFRecords at the given path(s).

Parameters
tf_records_pattthe path (or glob pattern of paths) to the TFRecords file(s) to load
buffer_size:Nonean optional buffer size, in bytes, to use when reading the records. Reasonable values are 1-100MBs
num_parallel_reads:Nonean optional number of files to read in parallel. If a negative value is passed, this parameter is set to the number of CPU cores on the host machine. By default, the files are read in series
Returns
a tf.data.Dataset that emits tf.train.Example protos
def write_tf_records(examples, tf_records_path, num_shards=None): (source)

Writes the given tf.train.Example protos to disk as TFRecords.

Parameters
examplesan iterable that emits tf.train.Example protos
tf_records_paththe path to write the .tfrecords file. If sharding is requested -%%05d-of-%%05d is appended to the path
num_shards:Nonean optional number of shards to split the records into (using a round robin strategy)

Undocumented

def _bytes_feature(value): (source)

Undocumented

def _bytes_list_feature(value): (source)

Undocumented

def _float_feature(value): (source)

Undocumented

def _float_list_feature(value): (source)

Undocumented

def _get_classes_for_detections(samples, label_field): (source)

Undocumented

def _int64_feature(value): (source)

Undocumented

def _int64_list_feature(value): (source)

Undocumented

def _parse_image_tf(image_path, force_rgb=False): (source)

Undocumented

def _to_labels_map_rev(classes): (source)

Undocumented