fiftyone.core.annotation.generate_label_schemas#

Annotation label schema generation

Copyright 2017-2026, Voxel51, Inc.

Functions:

generate_label_schemas(sample_collection[, ...])

Generates label schemas for a fiftyone.core.collections.SampleCollection.

fiftyone.core.annotation.generate_label_schemas.generate_label_schemas(sample_collection, fields=None, scan_samples=True)#

Generates label schemas for a fiftyone.core.collections.SampleCollection.

A label schema is defined by a type and component with respect to a field. Further settings depend on the type and component combination as outlined below.

The type value for a field is inferred from the collection’s field schema. See fiftyone.core.collections.SampleCollection.get_field_schema()

Currently supported media types for the collection are image and 3d. See fiftyone.core.collections.SampleCollection.media_type

Primitives and components

Supported primitive types are:

Supported bool components are:

  • checkbox

  • toggle - the default

date and datetime only support the datepicker component.

dict only supports the json component.

Supported float and int components are:

  • dropdown

  • radio

  • slider: the default when scan_samples is True and distinct finite bounds are found that define a range

  • text: the default when scan_samples is False or distinct finite bounds are not found

Supported list<float> and list<int> components are:

  • checkboxes

  • dropdown

  • text - the default

Supported list<str> components are:

  • checkboxes: the default if <=5 values are scanned

  • dropdown: the default if >5 and <=1000 values are scanned

  • text: the default if 0 values or >1000 values are scanned, or scan_samples is False

Supported str type components are:

  • dropdown: the default if >5 and <=1000 values are scanned

  • radio: the default if <=5 values are scanned

  • text: the default if 0 values or >1000 values are scanned, or scan_samples is False

float types support a precision setting when a text component is configured for the number of digits to allow after the decimal.

All types support a read_only flag. id types must be read_only. If a field is read_only in the field schema, then the read_only label schema setting must be True, e.g. created_at and last_modified_at must be read only.

All components support values except json, slider, and toggle excepting id restrictions.

checkboxes and dropdown require the values setting.

slider requires the range: [min, max] setting.

Labels

The label subfield of all label types are configured via classes and support the same settings as a str type. See the example output below for detections fields in the quickstart dataset. If the label type has a visual representation, that field is handled by the App’s builtin annotation UI, e.g. bounding_box for a detection. Primitive attributes of label types are configured via the attributes setting.

When a label is marked is read_only, all its attributes inherit the setting as well.

All fiftyone.core.labels.Label types are resolved by this method except fiftyone.core.labels.GeoLocation, fiftyone.core.labels.GeoLocations, fiftyone.core.labels.TemporalDetection, and fiftyone.core.labels.TemporalDetections when provided in the fields argument, otherwise only App supported fields are resolved. For label types supported by the App for annotation, see fiftyone.core.annotation.utils.get_supported_app_annotation_fields().

All attributes and the label class itself support a default setting that applies when creating a new label.

Embedded documents

One level of nesting is supported via dot.notation for fiftyone.core.fields.EmbeddedDocumentField` fields for the default metadata field and the fiftyone.core.odm.embedded_document.DynamicEmbeddedDocument` document type. All label and primitive types are supported. See here for more details on adding dynamic attributes.

Example:

import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart")
dataset.compute_metadata()

fo.pprint(fo.generate_label_schemas(dataset, scan_samples=True))

Output:

{
    'created_at': {
        'type': 'datetime',
        'component': 'datepicker',
        'read_only': True,
    },
    'filepath': {'type': 'str', 'component': 'text'},
    'ground_truth': {
        'attributes': {
            'attributes': {'type': 'dict', 'component': 'json'},
            'confidence': {'type': 'float', 'component': 'text'},
            'id': {
                'type': 'id',
                'component': 'text',
                'read_only': True
            },
            'index': {'type': 'int', 'component': 'text'},
            'mask_path': {'type': 'str', 'component': 'text'},
            'tags': {'type': 'list<str>', 'component': 'text'},
        },
        'classes': [
            'airplane',
            '...',
            'zebra',
        ],
        'component': 'dropdown',
        'type': 'detections',
    },
    'id': {'type': 'id', 'component': 'text', 'read_only': True},
    'last_modified_at': {
        'type': 'datetime',
        'component': 'datepicker',
        'read_only': True,
    },
    'metadata.height': {'type': 'int', 'component': 'text'},
    'metadata.mime_type': {'type': 'str', 'component': 'text'},
    'metadata.num_channels': {'type': 'int', 'component': 'text'},
    'metadata.size_bytes': {'type': 'int', 'component': 'text'},
    'metadata.width': {'type': 'int', 'component': 'text'},
    'predictions': {
        'attributes': {
            'attributes': {'type': 'dict', 'component': 'json'},
            'confidence': {
                'type': 'float',
                'component': 'slider',
                'range': [0.05003104358911514, 0.9999035596847534],
            },
            'id': {
                'type': 'id',
                'component': 'text',
                'read_only': True
            },
            'index': {'type': 'int', 'component': 'text'},
            'mask_path': {'type': 'str', 'component': 'text'},
            'tags': {'type': 'list<str>', 'component': 'text'},
        },
        'classes': [
            'airplane',
            '...',
            'zebra',
        ],
        'component': 'dropdown',
        'type': 'detections',
    },
    'tags': {
        'type': 'list<str>',
        'component': 'checkboxes',
        'values': ['validation'],
    },
    'uniqueness': {
        'type': 'float',
        'component': 'slider',
        'range': [0.15001302256126986, 1.0],
    },
}
Parameters:
  • sample_collection – the fiftyone.core.collections.SampleCollection to generate the schema with

  • fields (None) – a field name, embedded.field.name or iterable of such values

  • scan_samples (True) – whether to scan the collection to populate component settings based on actual field values (ranges, values, etc). If False, the label schema is generated from only the statically available information in the dataset’s field schema

Raises:

ValueError – if the sample collection or field is not supported

Returns:

a label schemas dict, or an individual field’s label schema dict if only one field is provided