# fiftyone.utils.data.exporters¶

Dataset exporters.

Classes:

 BatchDatasetExporter([export_dir]) Base interface for exporters that export entire fiftyone.core.collections.SampleCollection instances in a single batch. DatasetExporter([export_dir]) Base interface for exporting datsets. ExportPathsMixin Mixin for DatasetExporter classes that provides convenience methods for parsing the data_path, labels_path, and export_media parameters supported by many exporters. FiftyOneDatasetExporter(export_dir[, …]) Exporter that writes an entire FiftyOne dataset to disk in a serialized JSON format along with its source media. Exporter that writes an image classification dataset to disk in a simple JSON format. Exporter that writes an image detection dataset to disk in a simple JSON format. FiftyOneImageLabelsDatasetExporter(export_dir) Exporter that writes a labeled image dataset to disk with labels stored in ETA ImageLabels format. Exporter that writes a temporal video detection dataset to disk in a simple JSON format. FiftyOneVideoLabelsDatasetExporter(export_dir) Exporter that writes a labeled video dataset with labels stored in ETA VideoLabels format. GenericSampleDatasetExporter([export_dir]) Interface for exporting datasets of arbitrary fiftyone.core.sample.Sample instances. Exporter that writes an image classification directory tree to disk. ImageDirectoryExporter(export_dir[, …]) Exporter that writes a directory of images to disk. ImageExporter(*args[, default_ext]) Utility class for DatasetExporter instances that export images. Exporter that writes an image segmentation dataset to disk. LabeledImageDatasetExporter([export_dir]) Interface for exporting datasets of labeled image samples. LabeledVideoDatasetExporter([export_dir]) Interface for exporting datasets of labeled video samples. LegacyFiftyOneDatasetExporter(export_dir[, …]) Legacy exporter that writes an entire FiftyOne dataset to disk in a serialized JSON format along with its source media. MediaExporter(export_mode[, export_path, …]) Base class for DatasetExporter utilities that provide support for populating a directory or manifest of media files. UnlabeledImageDatasetExporter([export_dir]) Interface for exporting datasets of unlabeled image samples. UnlabeledVideoDatasetExporter([export_dir]) Interface for exporting datasets of unlabeled video samples. Exporter that writes a video classification directory tree to disk. VideoDirectoryExporter(export_dir[, …]) Exporter that writes a directory of videos to disk. VideoExporter(*args[, default_ext]) Utility class for DatasetExporter instances that export videos.

Functions:

 build_dataset_exporter(dataset_type[, …]) Builds the DatasetExporter instance for the given parameters. export_samples(samples[, export_dir, …]) Exports the given samples to disk. write_dataset(samples, sample_parser, …[, …]) Writes the samples to disk as a dataset in the specified format.
fiftyone.utils.data.exporters.export_samples(samples, export_dir=None, dataset_type=None, data_path=None, labels_path=None, export_media=None, dataset_exporter=None, label_field=None, frame_labels_field=None, num_samples=None, **kwargs)

Exports the given samples to disk.

You can perform exports with this method via the following basic patterns:

1. Provide export_dir and dataset_type to export the content to a directory in the default layout for the specified format, as documented in this page

2. Provide dataset_type along with data_path, labels_path, and/or export_media to directly specify where to export the source media and/or labels (if applicable) in your desired format. This syntax provides the flexibility to, for example, perform workflows like labels-only exports

3. Provide a dataset_exporter to which to feed samples to perform a fully-customized export

In all workflows, the remaining parameters of this method can be provided to further configure the export.

See this guide for more details about exporting datasets in custom formats by defining your own fiftyone.utils.data.exporters.DatasetExporter.

This method will automatically coerce the data to match the requested export in the following cases:

Parameters
• export_dir (None) – the directory to which to export the samples in format dataset_type

• dataset_type (None) – the fiftyone.types.dataset_types.Dataset type to write

• data_path (None) –

an optional parameter that enables explicit control over the location of the exported media for certain export formats. Can be any of the following:

• a folder name like "data" or "data/" specifying a subfolder of export_dir in which to export the media

• an absolute directory path in which to export the media. In this case, the export_dir has no effect on the location of the data

• a filename like "data.json" specifying the filename of a JSON manifest file in export_dir generated when export_media is "manifest"

• an absolute filepath specifying the location to write the JSON manifest file when export_media is "manifest". In this case, export_dir has no effect on the location of the data

If None, a default value of this parameter will be chosen based on the value of the export_media parameter. Note that this parameter is not applicable to certain export formats such as binary types like TF records

• labels_path (None) –

an optional parameter that enables explicit control over the location of the exported labels. Only applicable when exporting in certain labeled dataset formats. Can be any of the following:

• a type-specific folder name like "labels" or "labels/" or a filename like "labels.json" or "labels.xml" specifying the location in export_dir in which to export the labels

• an absolute directory or filepath in which to export the labels. In this case, the export_dir has no effect on the location of the labels

For labeled datasets, the default value of this parameter will be chosen based on the export format so that the labels will be exported into export_dir

• export_media (None) –

controls how to export the raw media. The supported values are:

• True: copy all media files into the output directory

• False: don’t export media. This option is only useful when exporting labeled datasets whose label format stores sufficient information to locate the associated media

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• "manifest": create a data.json in the output directory that maps UUIDs used in the labels files to the filepaths of the source media, rather than exporting the actual media

If None, an appropriate default value of this parameter will be chosen based on the value of the data_path parameter. Note that some dataset formats may not support certain values for this parameter (e.g., when exporting in binary formats such as TF records, “symlink” is not an option)

• dataset_exporter (None) – a DatasetExporter to use to write the dataset

• label_field (None) – the name of the label field to export, or a dictionary mapping field names to output keys describing the label fields to export. Only applicable if dataset_exporter is a LabeledImageDatasetExporter or LabeledVideoDatasetExporter, or if you are exporting image patches

• frame_labels_field (None) – the name of the frame label field to export, or a dictionary mapping field names to output keys describing the frame label fields to export. Only applicable if dataset_exporter is a LabeledVideoDatasetExporter

• num_samples (None) – the number of samples in samples. If omitted, this is computed (if possible) via len(samples)

• **kwargs – optional keyword arguments to pass to the dataset exporter’s constructor. If you are exporting image patches, this can also contain keyword arguments for fiftyone.utils.patches.ImagePatchesExtractor

fiftyone.utils.data.exporters.write_dataset(samples, sample_parser, dataset_exporter, num_samples=None, sample_collection=None)

Writes the samples to disk as a dataset in the specified format.

Parameters
fiftyone.utils.data.exporters.build_dataset_exporter(dataset_type, strip_none=True, warn_unused=True, **kwargs)

Builds the DatasetExporter instance for the given parameters.

Parameters
• dataset_type – the fiftyone.types.dataset_types.Dataset type

• strip_none (True) – whether to exclude None-valued items from kwargs

• warn_unused (True) – whether to issue warnings for any non-None unused parameters encountered

• **kwargs – keyword arguments to pass to the dataset exporter’s constructor via DatasetExporter(**kwargs)

Returns

Return type

a tuple of

class fiftyone.utils.data.exporters.ExportPathsMixin

Bases: object

Mixin for DatasetExporter classes that provides convenience methods for parsing the data_path, labels_path, and export_media parameters supported by many exporters.

class fiftyone.utils.data.exporters.MediaExporter(export_mode, export_path=None, supported_modes=None, default_ext=None, ignore_exts=False)

Bases: object

Base class for DatasetExporter utilities that provide support for populating a directory or manifest of media files.

This class is designed for populating a single, flat directory or manifest of media files, and automatically takes care of things like name clashes as necessary.

The export strategy used is defined by the export_mode parameter, and users of this class can restrict the available options via the supported_modes parameter.

Parameters
• export_mode

the export mode to use. The supported values are:

• True: copy all media files into the output directory

• False: don’t export media. This option is only useful when exporting labeled datasets whose label format stores sufficient information to locate the associated media

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• "manifest": create a data.json in the output directory that maps UUIDs used in the labels files to the filepaths of the source media, rather than exporting the actual media

• export_path (None) –

the location to export the media. Can be any of the following:

• When export_media is True, “move”, or “symlink”, a directory in which to export the media

• When export_mode is “manifest”, the path to write a JSON file mapping UUIDs to input filepaths

• When export_media is False, this parameter can optionally be a root directory to strip from each exported image’s path to yield a UUID for each image. If no path is provided, only the filename of each image is used for UUID generation

• supported_modes (None) – an optional tuple specifying a subset of the export_mode values that are allowed

• default_ext (None) – the file extension to use when generating default output paths

• ignore_exts (False) – whether to omit file extensions when generating UUIDs for files

Methods:

 Performs any necessary actions to complete the export. export(media_or_path[, outpath]) Exports the given media. Performs necessary setup to begin exporting media.
setup()

Performs necessary setup to begin exporting media.

DatasetExporter classes using this class should invoke this method in DatasetExporter.setup().

export(media_or_path, outpath=None)

Exports the given media.

Parameters
• media_or_path – the media or path to the media on disk

• outpath (None) – a manually-specified location to which to export the media. By default, the media will be exported into export_path

Returns

• the path to the exported media

• the UUID of the exported media

Return type

a tuple of

close()

Performs any necessary actions to complete the export.

class fiftyone.utils.data.exporters.ImageExporter(*args, default_ext=None, **kwargs)

Utility class for DatasetExporter instances that export images.

See MediaExporter for details.

Methods:

 Performs any necessary actions to complete the export. export(media_or_path[, outpath]) Exports the given media. Performs necessary setup to begin exporting media.
close()

Performs any necessary actions to complete the export.

export(media_or_path, outpath=None)

Exports the given media.

Parameters
• media_or_path – the media or path to the media on disk

• outpath (None) – a manually-specified location to which to export the media. By default, the media will be exported into export_path

Returns

• the path to the exported media

• the UUID of the exported media

Return type

a tuple of

setup()

Performs necessary setup to begin exporting media.

DatasetExporter classes using this class should invoke this method in DatasetExporter.setup().

class fiftyone.utils.data.exporters.VideoExporter(*args, default_ext=None, **kwargs)

Utility class for DatasetExporter instances that export videos.

See MediaExporter for details.

Methods:

 Performs any necessary actions to complete the export. export(media_or_path[, outpath]) Exports the given media. Performs necessary setup to begin exporting media.
close()

Performs any necessary actions to complete the export.

export(media_or_path, outpath=None)

Exports the given media.

Parameters
• media_or_path – the media or path to the media on disk

• outpath (None) – a manually-specified location to which to export the media. By default, the media will be exported into export_path

Returns

• the path to the exported media

• the UUID of the exported media

Return type

a tuple of

setup()

Performs necessary setup to begin exporting media.

DatasetExporter classes using this class should invoke this method in DatasetExporter.setup().

class fiftyone.utils.data.exporters.DatasetExporter(export_dir=None)

Bases: object

Base interface for exporting datsets.

Parameters

export_dir (None) – the directory to write the export. This may be optional for some exporters

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(*args, **kwargs) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.
setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

export_sample(*args, **kwargs)

Exports the given sample to the dataset.

Parameters
• *args – subclass-specific positional arguments

• **kwargs – subclass-specific keyword arguments

close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

class fiftyone.utils.data.exporters.BatchDatasetExporter(export_dir=None)

Base interface for exporters that export entire fiftyone.core.collections.SampleCollection instances in a single batch.

This interface allows for greater efficiency for export formats that handle aggregating over the samples themselves.

Parameters

export_dir (None) – the directory to write the export. This may be optional for some exporters

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(*args, **kwargs) Exports the given sample to the dataset. export_samples(sample_collection) Exports the given sample collection. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.
export_sample(*args, **kwargs)

Exports the given sample to the dataset.

Parameters
• *args – subclass-specific positional arguments

• **kwargs – subclass-specific keyword arguments

export_samples(sample_collection)

Exports the given sample collection.

Parameters

sample_collection – a fiftyone.core.collections.SampleCollection

close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

class fiftyone.utils.data.exporters.GenericSampleDatasetExporter(export_dir=None)

Interface for exporting datasets of arbitrary fiftyone.core.sample.Sample instances.

Parameters

export_dir (None) – the directory to write the export. This may be optional for some exporters

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(sample) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.
export_sample(sample)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

class fiftyone.utils.data.exporters.UnlabeledImageDatasetExporter(export_dir=None)

Interface for exporting datasets of unlabeled image samples.

Parameters

export_dir (None) – the directory to write the export. This may be optional for some exporters

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

export_sample(image_or_path, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

class fiftyone.utils.data.exporters.UnlabeledVideoDatasetExporter(export_dir=None)

Interface for exporting datasets of unlabeled video samples.

Parameters

export_dir (None) – the directory to write the export. This may be optional for some exporters

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(video_path[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 requires_video_metadata Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.
property requires_video_metadata

Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.

export_sample(video_path, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

class fiftyone.utils.data.exporters.LabeledImageDatasetExporter(export_dir=None)

Interface for exporting datasets of labeled image samples.

Parameters

export_dir (None) – the directory to write the export. This may be optional for some exporters

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path, label[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 label_cls The fiftyone.core.labels.Label class(es) exported by this exporter. requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) exported by this exporter.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can handle label dictionaries with value-types specified by this dictionary. Not all keys need be present in the exported label dicts

• None. In this case, the exporter makes no guarantees about the labels that it can export

export_sample(image_or_path, label, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

class fiftyone.utils.data.exporters.LabeledVideoDatasetExporter(export_dir=None)

Interface for exporting datasets of labeled video samples.

Parameters

export_dir (None) – the directory to write the export. This may be optional for some exporters

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(video_path, label, frames[, …]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 frame_labels_cls The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level. label_cls The fiftyone.core.labels.Label class(es) that can be exported at the sample-level. requires_video_metadata Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.
property requires_video_metadata

Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) that can be exported at the sample-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports sample-level labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single sample-level label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple label fields with value-types specified by this dictionary. Not all keys need be present in the exported sample-level labels

• None. In this case, the exporter makes no guarantees about the sample-level labels that it can export

property frame_labels_cls

The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports frame labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single frame label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple frame label fields with value-types specified by this dictionary. Not all keys need be present in the exported frame labels

• None. In this case, the exporter makes no guarantees about the frame labels that it can export

export_sample(video_path, label, frames, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

class fiftyone.utils.data.exporters.LegacyFiftyOneDatasetExporter(export_dir, export_media=None, relative_filepaths=True, pretty_print=False)

Legacy exporter that writes an entire FiftyOne dataset to disk in a serialized JSON format along with its source media.

Warning

The fiftyone.types.dataset_types.FiftyOneDataset format was upgraded in fiftyone==0.8 and this exporter is now deprecated. The new exporter is FiftyOneDatasetExporter.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

defines how to export the raw media contained in the dataset. The supported values are:

• True (default): copy all media files into the export directory

• False: don’t export media

• "move": move media files into the export directory

• "symlink": create symlinks to each media file in the export directory

• relative_filepaths (True) – whether to store relative (True) or absolute (False) filepaths to media files on disk in the output dataset

• pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(sample) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.
setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

export_sample(sample)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

class fiftyone.utils.data.exporters.FiftyOneDatasetExporter(export_dir, export_media=None, rel_dir=None)

Exporter that writes an entire FiftyOne dataset to disk in a serialized JSON format along with its source media.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

defines how to export the raw media contained in the dataset. The supported values are:

• True (default): copy all media files into the export directory

• False: don’t export media

• "move": move media files into the export directory

• "symlink": create symlinks to each media file in the export directory

• rel_dir (None) – a relative directory to remove from the filepath of each sample, if possible. The path is converted to an absolute path (if necessary) via fiftyone.core.utils.normalize_path(). The typical use case for this argument is that your source data lives in a single directory and you wish to serialize relative, rather than absolute, paths to the data within that directory. Only applicable when export_media is False

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(*args, **kwargs) Exports the given sample to the dataset. export_samples(sample_collection) Exports the given sample collection. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.
setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

export_samples(sample_collection)

Exports the given sample collection.

Parameters

sample_collection – a fiftyone.core.collections.SampleCollection

close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

export_sample(*args, **kwargs)

Exports the given sample to the dataset.

Parameters
• *args – subclass-specific positional arguments

• **kwargs – subclass-specific keyword arguments

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

class fiftyone.utils.data.exporters.ImageDirectoryExporter(export_dir, export_media=None, image_format=None)

Exporter that writes a directory of images to disk.

The filenames of input image paths will be maintained in the export directory, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

defines how to export the raw media contained in the dataset. The supported values are:

• True (default): copy all media files into the export directory

• "move": move media files into the export directory

• "symlink": create symlinks to each media file in the export directory

• image_format (None) – the image format to use when writing in-memory images to disk. By default, fiftyone.config.default_image_ext is used

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

export_sample(image_or_path, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

class fiftyone.utils.data.exporters.VideoDirectoryExporter(export_dir, export_media=None)

Exporter that writes a directory of videos to disk.

The filenames of the input videos will be maintained in the export directory, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

defines how to export the raw media contained in the dataset. The supported values are:

• True (default): copy all media files into the export directory

• "move": move media files into the export directory

• "symlink": create symlinks to each media file in the export directory

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(video_path[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 requires_video_metadata Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.
property requires_video_metadata

Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

export_sample(video_path, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

class fiftyone.utils.data.exporters.FiftyOneImageClassificationDatasetExporter(export_dir=None, data_path=None, labels_path=None, export_media=None, include_confidence=False, include_attributes=False, classes=None, image_format=None, pretty_print=False)

Exporter that writes an image classification dataset to disk in a simple JSON format.

If the path to an image is provided, the image is directly copied to its destination, maintaining the original filename, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir (None) – the directory to write the export. This has no effect if data_path and labels_path are absolute paths

• data_path (None) –

an optional parameter that enables explicit control over the location of the exported media. Can be any of the following:

• a folder name like "data" or "data/" specifying a subfolder of export_dir in which to export the media

• an absolute directory path in which to export the media. In this case, the export_dir has no effect on the location of the data

• a JSON filename like "data.json" specifying the filename of the manifest file in export_dir generated when export_media is "manifest"

• an absolute filepath specifying the location to write the JSON manifest file when export_media is "manifest". In this case, export_dir has no effect on the location of the data

If None, the default value of this parameter will be chosen based on the value of the export_media parameter

• labels_path (None) –

an optional parameter that enables explicit control over the location of the exported labels. Can be any of the following:

• a filename like "labels.json" specifying the location in export_dir in which to export the labels

• an absolute filepath to which to export the labels. In this case, the export_dir has no effect on the location of the labels

If None, the labels will be exported into export_dir using the default filename

• export_media (None) –

controls how to export the raw media. The supported values are:

• True: copy all media files into the output directory

• False: don’t export media

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• "manifest": create a data.json in the output directory that maps UUIDs used in the labels files to the filepaths of the source media, rather than exporting the actual media

If None, the default value of this parameter will be chosen based on the value of the data_path parameter

• include_confidence (False) –

whether to include classification confidences in the export. The supported values are:

• False (default): do not include confidences

• True: always include confidences

• None: include confidences only if they exist

• include_attributes (False) –

whether to include dynamic attributes of the classifications in the export. Supported values are:

• False (default): do not include attributes

• True: always include a (possibly empty) attributes dict

• None: include attributes only if they exist

• a name or iterable of names of specific attributes to include

• classes (None) – the list of possible class labels. If not provided, this list will be extracted when log_collection() is called, if possible

• image_format (None) – the image format to use when writing in-memory images to disk. By default, fiftyone.config.default_image_ext is used

• pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path, label[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 label_cls The fiftyone.core.labels.Label class(es) exported by this exporter. requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) exported by this exporter.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can handle label dictionaries with value-types specified by this dictionary. Not all keys need be present in the exported label dicts

• None. In this case, the exporter makes no guarantees about the labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

export_sample(image_or_path, label, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

class fiftyone.utils.data.exporters.ImageClassificationDirectoryTreeExporter(export_dir, export_media=None, image_format=None)

Exporter that writes an image classification directory tree to disk.

The filenames of the input images are maintained, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

controls how to export the raw media. The supported values are:

• True (default): copy all media files into the output directory

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• image_format (None) – the image format to use when writing in-memory images to disk. By default, fiftyone.config.default_image_ext is used

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path, classification) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 label_cls The fiftyone.core.labels.Label class(es) exported by this exporter. requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) exported by this exporter.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can handle label dictionaries with value-types specified by this dictionary. Not all keys need be present in the exported label dicts

• None. In this case, the exporter makes no guarantees about the labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

export_sample(image_or_path, classification, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

class fiftyone.utils.data.exporters.VideoClassificationDirectoryTreeExporter(export_dir, export_media=None)

Exporter that writes a video classification directory tree to disk.

The filenames of the input images are maintained, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

controls how to export the raw media. The supported values are:

• True (default): copy all media files into the output directory

• False: don’t export media

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(video_path, classification, _) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 frame_labels_cls The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level. label_cls The fiftyone.core.labels.Label class(es) that can be exported at the sample-level. requires_video_metadata Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.
property requires_video_metadata

Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) that can be exported at the sample-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports sample-level labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single sample-level label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple label fields with value-types specified by this dictionary. Not all keys need be present in the exported sample-level labels

• None. In this case, the exporter makes no guarantees about the sample-level labels that it can export

property frame_labels_cls

The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports frame labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single frame label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple frame label fields with value-types specified by this dictionary. Not all keys need be present in the exported frame labels

• None. In this case, the exporter makes no guarantees about the frame labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

export_sample(video_path, classification, _, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

class fiftyone.utils.data.exporters.FiftyOneImageDetectionDatasetExporter(export_dir=None, data_path=None, labels_path=None, export_media=None, classes=None, include_confidence=None, include_attributes=None, image_format=None, pretty_print=False)

Exporter that writes an image detection dataset to disk in a simple JSON format.

If the path to an image is provided, the image is directly copied to its destination, maintaining the original filename, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir (None) – the directory to write the export. This has no effect if data_path and labels_path are absolute paths

• data_path (None) –

an optional parameter that enables explicit control over the location of the exported media. Can be any of the following:

• a folder name like "data" or "data/" specifying a subfolder of export_dir in which to export the media

• an absolute directory path in which to export the media. In this case, the export_dir has no effect on the location of the data

• a JSON filename like "data.json" specifying the filename of the manifest file in export_dir generated when export_media is "manifest"

• an absolute filepath specifying the location to write the JSON manifest file when export_media is "manifest". In this case, export_dir has no effect on the location of the data

If None, the default value of this parameter will be chosen based on the value of the export_media parameter

• labels_path (None) –

an optional parameter that enables explicit control over the location of the exported labels. Can be any of the following:

• a filename like "labels.json" specifying the location in export_dir in which to export the labels

• an absolute filepath to which to export the labels. In this case, the export_dir has no effect on the location of the labels

If None, the labels will be exported into export_dir using the default filename

• export_media (None) –

controls how to export the raw media. The supported values are:

• True: copy all media files into the output directory

• False: don’t export media

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• "manifest": create a data.json in the output directory that maps UUIDs used in the labels files to the filepaths of the source media, rather than exporting the actual media

If None, the default value of this parameter will be chosen based on the value of the data_path parameter

• classes (None) – the list of possible class labels. If not provided, this list will be extracted when log_collection() is called, if possible

• include_confidence (None) –

whether to include detection confidences in the export. The supported values are:

• None (default): include confidences only if they exist

• True: always include confidences

• False: do not include confidences

• include_attributes (None) –

whether to include dynamic attributes of the detections in the export. Supported values are:

• None (default): include attributes only if they exist

• True: always include a (possibly empty) attributes dict

• False: do not include attributes

• a name or iterable of names of specific attributes to include

• image_format (None) – the image format to use when writing in-memory images to disk. By default, fiftyone.config.default_image_ext is used

• pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path, detections[, …]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 label_cls The fiftyone.core.labels.Label class(es) exported by this exporter. requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) exported by this exporter.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can handle label dictionaries with value-types specified by this dictionary. Not all keys need be present in the exported label dicts

• None. In this case, the exporter makes no guarantees about the labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

export_sample(image_or_path, detections, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

class fiftyone.utils.data.exporters.FiftyOneTemporalDetectionDatasetExporter(export_dir=None, data_path=None, labels_path=None, export_media=None, use_timestamps=False, classes=None, include_confidence=None, include_attributes=None, pretty_print=False)

Exporter that writes a temporal video detection dataset to disk in a simple JSON format.

Each input video is directly copied to its destination, maintaining the original filename, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir (None) – the directory to write the export. This has no effect if data_path and labels_path are absolute paths

• data_path (None) –

an optional parameter that enables explicit control over the location of the exported media. Can be any of the following:

• a folder name like "data" or "data/" specifying a subfolder of export_dir in which to export the media

• an absolute directory path in which to export the media. In this case, the export_dir has no effect on the location of the data

• a JSON filename like "data.json" specifying the filename of the manifest file in export_dir generated when export_media is "manifest"

• an absolute filepath specifying the location to write the JSON manifest file when export_media is "manifest". In this case, export_dir has no effect on the location of the data

If None, the default value of this parameter will be chosen based on the value of the export_media parameter

• labels_path (None) –

an optional parameter that enables explicit control over the location of the exported labels. Can be any of the following:

• a filename like "labels.json" specifying the location in export_dir in which to export the labels

• an absolute filepath to which to export the labels. In this case, the export_dir has no effect on the location of the labels

If None, the labels will be exported into export_dir using the default filename

• export_media (None) –

controls how to export the raw media. The supported values are:

• True: copy all media files into the output directory

• False: don’t export media

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• "manifest": create a data.json in the output directory that maps UUIDs used in the labels files to the filepaths of the source media, rather than exporting the actual media

If None, the default value of this parameter will be chosen based on the value of the data_path parameter

• use_timestamps (False) – whether to export the support of each temporal detection in seconds rather than frame numbers

• classes (None) – the list of possible class labels. If not provided, this list will be extracted when log_collection() is called, if possible

• include_confidence (None) –

whether to include detection confidences in the export. The supported values are:

• None (default): include confidences only if they exist

• True: always include confidences

• False: do not include confidences

• include_attributes (None) –

whether to include dynamic attributes of the detections in the export. Supported values are:

• None (default): include attributes only if they exist

• True: always include a (possibly empty) attributes dict

• False: do not include attributes

• a name or iterable of names of specific attributes to include

• pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(video_path, temporal_detections, _) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 frame_labels_cls The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level. label_cls The fiftyone.core.labels.Label class(es) that can be exported at the sample-level. requires_video_metadata Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.
property requires_video_metadata

Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) that can be exported at the sample-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports sample-level labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single sample-level label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple label fields with value-types specified by this dictionary. Not all keys need be present in the exported sample-level labels

• None. In this case, the exporter makes no guarantees about the sample-level labels that it can export

property frame_labels_cls

The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports frame labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single frame label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple frame label fields with value-types specified by this dictionary. Not all keys need be present in the exported frame labels

• None. In this case, the exporter makes no guarantees about the frame labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

export_sample(video_path, temporal_detections, _, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

class fiftyone.utils.data.exporters.ImageSegmentationDirectoryExporter(export_dir=None, data_path=None, labels_path=None, export_media=None, image_format=None, mask_format='.png', mask_size=None, mask_targets=None, thickness=1)

Exporter that writes an image segmentation dataset to disk.

If the path to an image is provided, the image is directly copied to its destination, maintaining the original filename, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir (None) – the directory to write the export. This has no effect if data_path and labels_path are absolute paths

• data_path (None) –

an optional parameter that enables explicit control over the location of the exported media. Can be any of the following:

• a folder name like "data" or "data/" specifying a subfolder of export_dir in which to export the media

• an absolute directory path in which to export the media. In this case, the export_dir has no effect on the location of the data

• a JSON filename like "data.json" specifying the filename of the manifest file in export_dir generated when export_media is "manifest"

• an absolute filepath specifying the location to write the JSON manifest file when export_media is "manifest". In this case, export_dir has no effect on the location of the data

If None, the default value of this parameter will be chosen based on the value of the export_media parameter

• labels_path (None) –

an optional parameter that enables explicit control over the location of the exported labels. Can be any of the following:

• a folder name like "labels" or "labels/" specifying the location in export_dir in which to export the masks

• an absolute directory in which to export the masks. In this case, the export_dir has no effect on the location of the masks

If None, the masks will be exported into export_dir using the default folder name

• export_media (None) –

controls how to export the raw media. The supported values are:

• True: copy all media files into the output directory

• False: don’t export media

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• "manifest": create a data.json in the output directory that maps UUIDs used in the labels files to the filepaths of the source media, rather than exporting the actual media

If None, the default value of this parameter will be chosen based on the value of the data_path parameter

• image_format (None) – the image format to use when writing in-memory images to disk. By default, fiftyone.config.default_image_ext is used

• mask_format (".png") – the image format to use when writing masks to disk

• mask_size (None) – the (width, height) at which to render segmentation masks when exporting instances or polylines. If not provided, masks will be rendered to match the resolution of each input image

• mask_targets (None) – a dict mapping integer pixel values in [0, 255] to label strings defining which object classes to render and which pixel values to use for each class. If omitted, all objects are rendered with pixel value 255

• thickness (1) – the thickness, in pixels, at which to render (non-filled) polylines

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path, label[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 label_cls The fiftyone.core.labels.Label class(es) exported by this exporter. requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) exported by this exporter.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can handle label dictionaries with value-types specified by this dictionary. Not all keys need be present in the exported label dicts

• None. In this case, the exporter makes no guarantees about the labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

export_sample(image_or_path, label, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

class fiftyone.utils.data.exporters.FiftyOneImageLabelsDatasetExporter(export_dir, export_media=None, image_format=None, pretty_print=False)

Exporter that writes a labeled image dataset to disk with labels stored in ETA ImageLabels format.

If the path to an image is provided, the image is directly copied to its destination, maintaining the original filename, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

controls how to export the raw media. The supported values are:

• True (default): copy all media files into the output directory

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• image_format (None) – the image format to use when writing in-memory images to disk. By default, fiftyone.config.default_image_ext is used

• pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(image_or_path, labels[, metadata]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 label_cls The fiftyone.core.labels.Label class(es) exported by this exporter. requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
property requires_image_metadata

Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) exported by this exporter.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can handle label dictionaries with value-types specified by this dictionary. Not all keys need be present in the exported label dicts

• None. In this case, the exporter makes no guarantees about the labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

export_sample(image_or_path, labels, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()

class fiftyone.utils.data.exporters.FiftyOneVideoLabelsDatasetExporter(export_dir, export_media=None, pretty_print=False)

Exporter that writes a labeled video dataset with labels stored in ETA VideoLabels format.

If the path to a video is provided, the video is directly copied to its destination, maintaining the original filename, unless a name conflict would occur, in which case an index of the form "-%d" % count is appended to the base filename.

Parameters
• export_dir – the directory to write the export

• export_media (None) –

controls how to export the raw media. The supported values are:

• True (default): copy all media files into the output directory

• "move": move all media files into the output directory

• "symlink": create symlinks to the media files in the output directory

• pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Methods:

 close(*args) Performs any necessary actions after the last sample has been exported. export_sample(video_path, label, frames[, …]) Exports the given sample to the dataset. log_collection(sample_collection) Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported. Performs any necessary setup before exporting the first sample in the dataset.

Attributes:

 frame_labels_cls The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level. label_cls The fiftyone.core.labels.Label class(es) that can be exported at the sample-level. requires_video_metadata Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.
property requires_video_metadata

Whether this exporter requires fiftyone.core.metadata.VideoMetadata instances for each sample being exported.

property label_cls

The fiftyone.core.labels.Label class(es) that can be exported at the sample-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports sample-level labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single sample-level label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple label fields with value-types specified by this dictionary. Not all keys need be present in the exported sample-level labels

• None. In this case, the exporter makes no guarantees about the sample-level labels that it can export

property frame_labels_cls

The fiftyone.core.labels.Label class(es) that can be exported by this exporter at the frame-level.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the exporter directly exports frame labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the exporter can export a single frame label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the exporter can export multiple frame label fields with value-types specified by this dictionary. Not all keys need be present in the exported frame labels

• None. In this case, the exporter makes no guarantees about the frame labels that it can export

setup()

Performs any necessary setup before exporting the first sample in the dataset.

This method is called when the exporter’s context manager interface is entered, DatasetExporter.__enter__().

log_collection(sample_collection)

Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.

Subclasses can optionally implement this method if their export format can record information such as the fiftyone.core.collections.SampleCollection.info() or fiftyone.core.collections.SampleCollection.classes() of the collection being exported.

By convention, this method must be optional; i.e., if it is not called before the first call to export_sample(), then the exporter must make do without any information about the fiftyone.core.collections.SampleCollection (which may not be available, for example, if the samples being exported are not stored in a collection).

Parameters

sample_collection – the fiftyone.core.collections.SampleCollection whose samples will be exported

export_sample(video_path, label, frames, metadata=None)

Exports the given sample to the dataset.

Parameters
close(*args)

Performs any necessary actions after the last sample has been exported.

This method is called when the exporter’s context manager interface is exited, DatasetExporter.__exit__().

Parameters

*args – the arguments to DatasetExporter.__exit__()