class documentation

Exporter that writes COCO detection datasets to disk.

See :ref:`this page <COCODetectionDataset-export>` for format details.

Parameters
export_dirthe directory to write the export. This has no effect if data_path and labels_path are absolute paths
data_path

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

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

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

rel_diran optional relative directory to strip from each input filepath to generate a unique identifier for each image. When exporting media, this identifier is joined with data_path to generate an output path for each exported image. This argument allows for populating nested subdirectories that match the shape of the input paths. The path is converted to an absolute path (if necessary) via fiftyone.core.storage.normalize_path
abs_pathswhether to store absolute paths to the images in the exported labels
image_formatthe image format to use when writing in-memory images to disk. By default, fiftyone.config.default_image_ext is used
classesthe list of possible class labels
categoriesa list of category dicts in the format of parse_coco_categories specifying the classes and their category IDs
infoa dict of info as returned by load_coco_detection_annotations to include in the exported JSON. If not provided, this info will be extracted when log_collection is called, if possible
extra_attrs

whether to include extra object attributes in the exported labels. Supported values are:

  • True: export all extra attributes found
  • False: do not export extra attributes
  • a name or list of names of specific attributes to export
coco_idthe name of a sample field containing the COCO IDs of each image
annotation_idthe name of a label field containing the COCO annotation ID of each label
iscrowdthe name of a detection attribute that indicates whether an object is a crowd (the value is automatically set to 0 if the attribute is not present)
num_decimalsan optional number of decimal places at which to round bounding box pixel coordinates. By default, no rounding is done
tolerancea tolerance, in pixels, when generating approximate polylines for instance masks. Typical values are 1-3 pixels
Method __init__ Undocumented
Method close Performs any necessary actions after the last sample has been exported.
Method export_sample Exports the given sample to the dataset.
Method log_collection Logs any relevant information about the fiftyone.core.collections.SampleCollection whose samples will be exported.
Method setup Performs any necessary setup before exporting the first sample in the dataset.
Instance Variable abs_paths Undocumented
Instance Variable annotation_id Undocumented
Instance Variable categories Undocumented
Instance Variable classes Undocumented
Instance Variable coco_id Undocumented
Instance Variable data_path Undocumented
Instance Variable export_media Undocumented
Instance Variable extra_attrs Undocumented
Instance Variable image_format Undocumented
Instance Variable info Undocumented
Instance Variable iscrowd Undocumented
Instance Variable labels_path Undocumented
Instance Variable num_decimals Undocumented
Instance Variable rel_dir Undocumented
Instance Variable tolerance Undocumented
Property label_cls The fiftyone.core.labels.Label class(es) exported by this exporter.
Property requires_image_metadata Whether this exporter requires fiftyone.core.metadata.ImageMetadata instances for each sample being exported.
Method _parse_classes Undocumented
Instance Variable _anno_id Undocumented
Instance Variable _annotations Undocumented
Instance Variable _classes Undocumented
Instance Variable _dynamic_classes Undocumented
Instance Variable _has_labels Undocumented
Instance Variable _image_id Undocumented
Instance Variable _image_id_map Undocumented
Instance Variable _images Undocumented
Instance Variable _labels_map_rev Undocumented
Instance Variable _media_exporter Undocumented

Inherited from DatasetExporter (via LabeledImageDatasetExporter):

Method __enter__ Undocumented
Method __exit__ Undocumented

Inherited from ExportPathsMixin (via LabeledImageDatasetExporter, DatasetExporter):

Static Method _parse_data_path Helper function that computes default values for the data_path and export_media parameters supported by many exporters.
Static Method _parse_labels_path Helper function that computes default values for the labels_path parameter supported by many exporters.
def __init__(self, export_dir=None, data_path=None, labels_path=None, export_media=None, rel_dir=None, abs_paths=False, image_format=None, classes=None, categories=None, info=None, extra_attrs=True, coco_id=None, annotation_id=None, iscrowd='iscrowd', num_decimals=None, tolerance=None): (source)
def close(self, *args): (source)

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
*argsthe arguments to DatasetExporter.__exit__
def export_sample(self, image_or_path, label, metadata=None): (source)

Exports the given sample to the dataset.

Parameters
image_or_pathan image or the path to the image on disk
labelan instance of label_cls, or a dictionary mapping field names to fiftyone.core.labels.Label instances, or None if the sample is unlabeled
metadata:Nonea fiftyone.core.metadata.ImageMetadata instance for the sample. Only required when requires_image_metadata is True
def log_collection(self, sample_collection): (source)

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 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_collectionthe fiftyone.core.collections.SampleCollection whose samples will be exported
def setup(self): (source)

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__.

abs_paths: False = (source)

Undocumented

annotation_id: None = (source)

Undocumented

categories: None = (source)

Undocumented

Undocumented

Undocumented

data_path: None = (source)

Undocumented

export_media: None = (source)

Undocumented

extra_attrs: True = (source)

Undocumented

image_format: None = (source)

Undocumented

Undocumented

iscrowd: "iscrowd" = (source)

Undocumented

labels_path: None = (source)

Undocumented

num_decimals: None = (source)

Undocumented

Undocumented

tolerance: None = (source)

Undocumented

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
@property
requires_image_metadata = (source)

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

def _parse_classes(self): (source)

Undocumented

_anno_id: int = (source)

Undocumented

_annotations: list = (source)

Undocumented

_classes = (source)

Undocumented

_dynamic_classes: bool = (source)

Undocumented

_has_labels: bool = (source)

Undocumented

_image_id: int = (source)

Undocumented

_image_id_map = (source)

Undocumented

Undocumented

_labels_map_rev = (source)

Undocumented

_media_exporter = (source)

Undocumented