Skip to content

pixano.app.models.annotations

AnnotationModel(created_at=None, updated_at=None, **data)

Bases: BaseSchemaModel[Annotation]

Model for the Annotation schema.

Source code in pixano/app/models/base_schema.py
def __init__(self, /, created_at: datetime | None = None, updated_at: datetime | None = None, **data: Any):
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.

    Args:
        created_at: The creation date of the object.
        updated_at: The last modification date of the object.
        data: The data of the object validated by Pydantic.
    """
    created_at, updated_at = validate_and_init_create_at_and_update_at(created_at, updated_at)
    data.update({"created_at": created_at, "updated_at": updated_at})
    super().__init__(**data)

from_row(row, table_info) classmethod

Create an AnnotationModel from an Annotation.

Parameters:

Name Type Description Default
row Annotation

The row to create the model from.

required
table_info TableInfo

The table info of the row.

required

Returns:

Type Description
Self

The created model.

Source code in pixano/app/models/annotations.py
@classmethod
def from_row(cls, row: Annotation, table_info: TableInfo) -> Self:
    """Create an AnnotationModel from an [Annotation][pixano.features.Annotation].

    Args:
        row: The row to create the model from.
        table_info: The table info of the row.

    Returns:
        The created model.
    """
    annotation_model = BaseSchemaModel.from_row(row, table_info)
    annotation_model.data["inference_metadata"] = json.loads(row.inference_metadata)
    return cls.model_construct(**annotation_model.__dict__)  # Avoid validation and casting

to_row(dataset)

Create an Annotation from the model.

Source code in pixano/app/models/annotations.py
def to_row(self, dataset: Dataset) -> Annotation:
    """Create an [Annotation][pixano.features.Annotation] from the model."""
    if not is_annotation(dataset.schema.schemas[self.table_info.name]):
        raise ValueError(f"Schema type must be a subclass of {Annotation.__name__}.")
    row = super().to_row(dataset)
    row.inference_metadata = json.dumps(self.data["inference_metadata"])
    return row