fiftyone.core.ontology#
Ontology classes for defining reusable annotation and taxonomy structures.
Classes:
|
Abstract base class for ontology types. |
|
Ontology for defining annotation structures. |
|
Ontology for defining a hierarchical class structure. |
|
One dataset's |
Functions:
|
Saves the given ontology to the database. |
|
Loads the latest version of an ontology by name. |
|
Lists ontology names in the database. |
|
Checks if an ontology with the given name exists. |
|
Deletes an ontology and all its versions from the database. |
|
Returns a new |
- class fiftyone.core.ontology.Ontology(name: str, description: str | None = None)#
Bases:
ABCAbstract base class for ontology types.
Ontologies are global, named, versioned resources that define reusable annotation structures. They are not scoped to any single dataset.
save()andload()populateversion,created_at, andlast_modified_at.- Parameters:
name – the ontology name
description – optional description
Attributes:
The version of this ontology, or
Noneif not yet saved.The datetime this ontology was created, or
Noneif not yet saved.The datetime this ontology was last modified, or
Noneif not yet saved.Whether this ontology is an annotation ontology.
Whether this ontology is a taxonomy.
Methods:
save([overwrite])Saves this ontology to the database.
reload()Reloads this ontology from the database.
delete()Deletes this ontology from the database.
clone(new_name)Clones this ontology under a new name.
to_dict()Serializes this ontology to a dict.
from_dict(d)Creates an ontology from a dict.
- property version: int | None#
The version of this ontology, or
Noneif not yet saved.
- property created_at: datetime | None#
The datetime this ontology was created, or
Noneif not yet saved.
- property last_modified_at: datetime | None#
The datetime this ontology was last modified, or
Noneif not yet saved.
- save(overwrite: bool = False) None#
Saves this ontology to the database.
- Parameters:
overwrite – if True and an ontology with this name already exists in the database, adopt its lineage and append a new version. Enables JSON/git-driven workflows where an instance built via
from_dict()is saved without first callingload_ontology(). With the defaultFalse, saving an in-memory instance whose slug collides with a persisted ontology is rejected.
- reload() None#
Reloads this ontology from the database.
- delete() None#
Deletes this ontology from the database.
- clone(new_name: str) Ontology#
Clones this ontology under a new name.
- Parameters:
new_name – the name for the clone
- Returns:
the cloned
Ontology
- to_dict() dict#
Serializes this ontology to a dict.
- Returns:
a dict
- class fiftyone.core.ontology.AnnotationOntology(name: str, description: str | None = None, taxonomy: Taxonomy | None = None, attributes: list[AttributeSpec] | None = None)#
Bases:
OntologyOntology for defining annotation structures.
Bundles typed attributes (with optional conditional display logic) and an optional taxonomy reference into a single document that gets connected to a label schema on a field.
- Parameters:
name – the ontology name
description – optional description
taxonomy – optional
Taxonomyinstance to bundle with this ontology. Stored internally as the taxonomy’s slug.attributes – list of
AttributeSpecinstances
Example:
vehicle_classes = Taxonomy( name="vehicle_classes", root=Node(name="root", values=[Node(name="car")]), ) AnnotationOntology( name="vehicle_damage_ontology", description="Vehicle damage annotation", taxonomy=vehicle_classes, attributes=[ AttributeSpec( name="damage_present", type="bool", component="checkbox", ), AttributeSpec( name="damage_location", type="str", component="dropdown", values=["front", "rear", "driver_side", "passenger_side"], when=WhenEquals(field="damage_present", value=True), ), ], )
Methods:
to_dict()Serializes this annotation ontology to a dict.
from_dict(d)Creates an
AnnotationOntologyfrom a dict.clone(new_name)Clones this ontology under a new name.
delete()Deletes this ontology from the database.
reload()Reloads this ontology from the database.
save([overwrite])Saves this ontology to the database.
Attributes:
The datetime this ontology was created, or
Noneif not yet saved.Whether this ontology is an annotation ontology.
Whether this ontology is a taxonomy.
The datetime this ontology was last modified, or
Noneif not yet saved.The version of this ontology, or
Noneif not yet saved.- to_dict() dict#
Serializes this annotation ontology to a dict.
- Returns:
a dict
- classmethod from_dict(d: dict) AnnotationOntology#
Creates an
AnnotationOntologyfrom a dict.- Parameters:
d – an annotation ontology dict
- Returns:
- clone(new_name: str) Ontology#
Clones this ontology under a new name.
- Parameters:
new_name – the name for the clone
- Returns:
the cloned
Ontology
- property created_at: datetime | None#
The datetime this ontology was created, or
Noneif not yet saved.
- delete() None#
Deletes this ontology from the database.
- property last_modified_at: datetime | None#
The datetime this ontology was last modified, or
Noneif not yet saved.
- reload() None#
Reloads this ontology from the database.
- save(overwrite: bool = False) None#
Saves this ontology to the database.
- Parameters:
overwrite – if True and an ontology with this name already exists in the database, adopt its lineage and append a new version. Enables JSON/git-driven workflows where an instance built via
from_dict()is saved without first callingload_ontology(). With the defaultFalse, saving an in-memory instance whose slug collides with a persisted ontology is rejected.
- property version: int | None#
The version of this ontology, or
Noneif not yet saved.
- class fiftyone.core.ontology.Taxonomy(name: str, root: Node, description: str | None = None)#
Bases:
OntologyOntology for defining a hierarchical class structure.
A taxonomy is a named, versioned, self-contained class hierarchy. Label schema fields reference a taxonomy by
nameinstead of inlining a flat class list, so the same hierarchy can be shared across multiple datasets.- Parameters:
name – the taxonomy name
description – optional description
root – the root
Nodeof the hierarchy. Required.
Example:
Taxonomy( name="vehicle_classes", root=Node( name="vehicles", can_select=False, values=[ Node(name="car"), Node(name="truck"), Node(name="motorcycle"), ], ), )
Methods:
to_dict()Serializes this taxonomy to a dict.
from_dict(d)Creates a
Taxonomyfrom a dict.clone(new_name)Clones this ontology under a new name.
delete()Deletes this ontology from the database.
reload()Reloads this ontology from the database.
save([overwrite])Saves this ontology to the database.
Attributes:
The datetime this ontology was created, or
Noneif not yet saved.Whether this ontology is an annotation ontology.
Whether this ontology is a taxonomy.
The datetime this ontology was last modified, or
Noneif not yet saved.The version of this ontology, or
Noneif not yet saved.- to_dict() dict#
Serializes this taxonomy to a dict.
- Returns:
a dict
- classmethod from_dict(d: dict) Taxonomy#
Creates a
Taxonomyfrom a dict.- Parameters:
d – a taxonomy dict
- Returns:
a
Taxonomy
- clone(new_name: str) Ontology#
Clones this ontology under a new name.
- Parameters:
new_name – the name for the clone
- Returns:
the cloned
Ontology
- property created_at: datetime | None#
The datetime this ontology was created, or
Noneif not yet saved.
- delete() None#
Deletes this ontology from the database.
- property last_modified_at: datetime | None#
The datetime this ontology was last modified, or
Noneif not yet saved.
- reload() None#
Reloads this ontology from the database.
- save(overwrite: bool = False) None#
Saves this ontology to the database.
- Parameters:
overwrite – if True and an ontology with this name already exists in the database, adopt its lineage and append a new version. Enables JSON/git-driven workflows where an instance built via
from_dict()is saved without first callingload_ontology(). With the defaultFalse, saving an in-memory instance whose slug collides with a persisted ontology is rejected.
- property version: int | None#
The version of this ontology, or
Noneif not yet saved.
- fiftyone.core.ontology.save_ontology(ontology: Ontology, overwrite: bool = False) None#
Saves the given ontology to the database.
Module-level mirror of
Ontology.save(), paired withload_ontology()anddelete_ontology().- Parameters:
ontology – an
Ontologyto saveoverwrite – see
Ontology.save()
- fiftyone.core.ontology.load_ontology(name: str) Ontology#
Loads the latest version of an ontology by name.
- Parameters:
name – the ontology name
- Returns:
an
Ontology- Raises:
ValueError – if no ontology with the given name exists
- fiftyone.core.ontology.list_ontologies(glob_patt: str | None = None) list[str]#
Lists ontology names in the database.
- Parameters:
glob_patt – an optional glob pattern to filter names
- Returns:
a sorted list of ontology names
- fiftyone.core.ontology.ontology_exists(name: str) bool#
Checks if an ontology with the given name exists.
- Parameters:
name – the ontology name
- Returns:
True/False
- class fiftyone.core.ontology.LabelSchemaOntologyRef(dataset_id: str, field_names: list[str])#
Bases:
NamedTupleOne dataset’s
applied_ontologyreferences for a given ontology.- dataset_id#
the
DatasetDocumentid (string form)- Type:
str
- field_names#
the label-schema field names on that dataset that reference the ontology
- Type:
list[str]
Attributes:
Alias for field number 0
Alias for field number 1
Methods:
count(value, /)Return number of occurrences of value.
index(value[, start, stop])Return first index of value.
- dataset_id: str#
Alias for field number 0
- count(value, /)#
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)#
Return first index of value.
Raises ValueError if the value is not present.
- fiftyone.core.ontology.delete_ontology(name: str, force: bool = False) None#
Deletes an ontology and all its versions from the database.
If any label schema references this ontology (via
applied_ontologyon a field), the default behavior is to raise rather than silently break those schemas. Passforce=Trueto inline the ontology’s attributes into each affected schema as permanent local copies and then delete the ontology.Inlining and deletion run as two phases: every affected schema is inlined and saved first, and the ontology is deleted only if every save succeeds. If something fails mid-inline, the ontology still exists and the call is safely re-runnable — already-inlined schemas no longer match the lookup.
- Parameters:
name – the ontology name
force – if False (default), raise if any label schema references the ontology. If True, inline the ontology’s attributes into each affected schema as local copies before deleting.
- Raises:
ValueError – if the ontology does not exist, or if it is in use and
force=False
- fiftyone.core.ontology.apply_ontology(label_schemas: dict, field_name: str, ontology_name: str | None) dict#
Returns a new
label_schemasdict with an annotation ontology attached to (or removed from) the given field.Pure function — does not mutate the input. Apply the result via
fiftyone.core.dataset.Dataset.set_label_schemas()to persist.- Parameters:
label_schemas – a label schemas dict
field_name – the field to attach the ontology to
ontology_name – name of an annotation ontology to attach, or
Noneto unset an existing reference
- Returns:
a new label schemas dict