fiftyone.core.annotation.hydrate_label_schemas#
Annotation label schema hydration
Resolves applied_ontology references in label schemas by merging the
referenced annotation ontology’s attributes into the schema’s attributes
list, tagging merged attributes with a _source marker.
Functions:
|
Returns ontology attributes as dicts tagged with a |
|
Merges a referenced annotation ontology's attributes into a label schema. |
|
Strips hydration artifacts from a label schema before it is saved. |
|
Permanently inlines an annotation ontology's attributes into a label schema as local copies and removes the |
- fiftyone.core.annotation.hydrate_label_schemas.attributes_with_source(ontology: Any) list[dict[str, Any]]#
Returns ontology attributes as dicts tagged with a
_sourcemarker.- Parameters:
ontology – an ontology object whose
.attributesare attribute specs with a.to_dict()method and whose.nameidentifies the ontology- Returns:
a list of attribute dicts, each carrying
_source: ontology.name
- fiftyone.core.annotation.hydrate_label_schemas.hydrate_applied_ontology(label_schema: dict) dict#
Merges a referenced annotation ontology’s attributes into a label schema.
If
label_schemahas anapplied_ontologykey that resolves to an annotation ontology, returns a new dict with the ontology’s attributes merged into theattributeslist. Each merged attribute carries a_source: <ontology_name>marker. Attributes are matched bynameand ontology values win on collision.If the schema has no
applied_ontologyreference, the schema is returned unchanged. If the reference is dangling (deleted ontology) or points at a non-annotation ontology, theapplied_ontologykey is stripped from the returned schema and a WARNING is logged. This lets a subsequent save silently persist a clean schema rather than failing validation on the dangling reference.- Parameters:
label_schema – a label schema dict
- Returns:
a hydrated copy of
label_schema, a copy withapplied_ontologystripped if the reference is dangling, or the schema unchanged when there is nothing to do
- fiftyone.core.annotation.hydrate_label_schemas.dehydrate_applied_ontology(label_schema: dict) dict#
Strips hydration artifacts from a label schema before it is saved.
Companion to
hydrate_applied_ontology(). When the schema has anapplied_ontologythat resolves to an annotation ontology, drops any attribute whosenamematches an ontology-owned attribute and strips the_sourcemarker from the remaining attributes.Otherwise (no reference, dangling reference, or non-annotation reference) the schema is returned unchanged — the validator will surface the reference-level problem.
- Parameters:
label_schema – a label schema dict, possibly carrying hydration artifacts from
hydrate_applied_ontology()- Returns:
a deep-copied schema with hydration artifacts removed, or
label_schemaunchanged when there is nothing to dehydrate
- fiftyone.core.annotation.hydrate_label_schemas.inline_applied_ontology(label_schema: dict, ontology: Any) dict#
Permanently inlines an annotation ontology’s attributes into a label schema as local copies and removes the
applied_ontologyreference.Used when the referenced ontology is about to be deleted (or for any other “freeze the current ontology state into the schema” operation). Unlike
hydrate_applied_ontology(), the merged attributes are NOT marked with_source— they are now first-class local attributes — and theapplied_ontologykey is stripped from the result.The caller is responsible for resolving the ontology; this function does not load anything.
- Parameters:
label_schema – a label schema dict
ontology – an
AnnotationOntologywhose attributes should be inlined
- Returns:
a deep-copied schema with the ontology’s attributes merged in as locals and the
applied_ontologyreference removed