Skip to content

pixano.features.schemas.annotations.classification

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

Bases: Annotation

Classification at the media level (Image or Text).

Attributes:

Name Type Description
labels list[str]

List of class names.

confidences list[float]

List of prediction confidences.

Source code in pixano/features/schemas/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)

predictions property

Get list of zipped predictions (labels and confidences).

none() classmethod

Utility function to get a None equivalent. Should be removed as soon as Lance manages None value.

Returns:

Type Description
Classification

"None" Classification.

Source code in pixano/features/schemas/annotations/classification.py
@classmethod
def none(cls) -> "Classification":
    """Utility function to get a `None` equivalent.
    Should be removed as soon as Lance manages `None` value.

    Returns:
        "None" Classification.
    """
    return cls(
        id="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        labels=[],
        confidences=[],
    )

create_classification(labels, confidences, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a Classification instance.

Parameters:

Name Type Description Default
labels list[str]

List of class names.

required
confidences list[float]

List of prediction confidences.

required
id str

Classification ID.

''
item_ref ItemRef

Item reference.

none()
view_ref ViewRef

View reference.

none()
entity_ref EntityRef

Entity reference.

none()
source_ref SourceRef

Source reference.

none()

Returns:

Type Description
Classification

The created Classification instance.

Source code in pixano/features/schemas/annotations/classification.py
def create_classification(
    labels: list[str],
    confidences: list[float],
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
) -> Classification:
    """Create a `Classification` instance.

    Args:
        labels: List of class names.
        confidences: List of prediction confidences.
        id: `Classification` ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

    Returns:
        The created `Classification` instance.
    """
    return Classification(
        labels=labels,
        confidences=confidences,
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
    )

is_classification(cls, strict=False)

Check if a class is a Classification or subclass of Classification.

Source code in pixano/features/schemas/annotations/classification.py
def is_classification(cls: type, strict: bool = False) -> bool:
    """Check if a class is a `Classification` or subclass of `Classification`."""
    return issubclass_strict(cls, Classification, strict)