fiftyone.core.annotation.generate_label_schemas#
Annotation label schema generation
Functions:
|
Generates label schemas for a |
- 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
typeandcomponentwith respect to a field. Further settings depend on thetypeandcomponentcombination as outlined below.The
typevalue for a field is inferred from the collection’s field schema. Seefiftyone.core.collections.SampleCollection.get_field_schema()Currently supported media types for the collection are
imageand3d. Seefiftyone.core.collections.SampleCollection.media_typePrimitives and components
Supported primitive types are:
datetime:fiftyone.core.fields.DateTimeFieldid:fiftyone.core.fields.ObjectIdFieldorfiftyone.core.fields.UUIDFieldint:fiftyone.core.fields.IntFieldorfiftyone.core.fields.FrameNumberFieldlist<int>:fiftyone.core.fields.ListFieldoffiftyone.core.fields.IntFieldlist<float>:fiftyone.core.fields.ListFieldoffiftyone.core.fields.FloatFieldlist<str>:fiftyone.core.fields.ListFieldoffiftyone.core.fields.StringField
Supported
boolcomponents are:checkboxtoggle- the default
dateanddatetimeonly support thedatepickercomponent.dictonly supports thejsoncomponent.Supported
floatandintcomponents are:dropdownradioslider: the default whenscan_samplesisTrueand distinct finite bounds are found that define arangetext: the default whenscan_samplesisFalseor distinct finite bounds are not found
Supported
list<float>andlist<int>components are:checkboxesdropdowntext- the default
Supported
list<str>components are:checkboxes: the default if<=5values are scanneddropdown: the default if>5and<=1000values are scannedtext: the default if0values or>1000values are scanned, orscan_samplesisFalse
Supported
strtype components are:dropdown: the default if>5and<=1000values are scannedradio: the default if<=5values are scannedtext: the default if0values or>1000values are scanned, orscan_samplesisFalse
floattypes support aprecisionsetting when atextcomponent is configured for the number of digits to allow after the decimal.All types support a
read_onlyflag.idtypes must beread_only. If a field isread_onlyin the field schema, then theread_onlylabel schema setting must beTrue, e.g.created_atandlast_modified_atmust be read only.All components support
valuesexceptjson,slider, andtoggleexceptingidrestrictions.checkboxesanddropdownrequire thevaluessetting.sliderrequires therange: [min, max]setting.Labels
The
labelsubfield of all label types are configured viaclassesand support the same settings as astrtype. See the example output below fordetectionsfields 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_boxfor adetection. Primitive attributes of label types are configured via theattributessetting.When a label is marked is
read_only, all its attributes inherit the setting as well.All
fiftyone.core.labels.Labeltypes are resolved by this method exceptfiftyone.core.labels.GeoLocation,fiftyone.core.labels.GeoLocations,fiftyone.core.labels.TemporalDetection, andfiftyone.core.labels.TemporalDetectionswhen provided in thefieldsargument, otherwise only App supported fields are resolved. For label types supported by the App for annotation, seefiftyone.core.annotation.utils.get_supported_app_annotation_fields().All attributes and the label class itself support a
defaultsetting that applies when creating a new label.Embedded documents
One level of nesting is supported via
dot.notationforfiftyone.core.fields.EmbeddedDocumentField`fields for the defaultmetadatafield and thefiftyone.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.SampleCollectionto generate the schema withfields (None) – a field name,
embedded.field.nameor iterable of such valuesscan_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 schemadictif only one field is provided