Skip to content

pixano.features.schemas.annotations.keypoints

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

Bases: Annotation

A set of keypoints.

Attributes:

Name Type Description
template_id str

Id of the keypoint template.

coords list[float]

List of 2D coordinates of the keypoints.

states list[str]

Status for each keypoint. ("visible", "invisible", "hidden").

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)

map_back2front_vertices()

Utility function to map back format for KeyPoint to front vertices format.

Raises:

Type Description
ValueError

If keypoints is ill-formed.

Returns:

Type Description
list

keypoint list for vertices front format.

Source code in pixano/features/schemas/annotations/keypoints.py
def map_back2front_vertices(self) -> list:
    """Utility function to map back format for KeyPoint to front vertices format.

    Raises:
        ValueError: If keypoints is ill-formed.

    Returns:
        keypoint list for vertices front format.
    """
    # Check coords are even
    if len(self.coords) % 2 != 0:
        raise ValueError("There must be an even number of coords")

    result = []
    if self.states is not None:
        num_points = len(self.coords) // 2
        if len(self.states) != num_points:
            raise ValueError("There must be the same number of states than points")

        result = [
            {"x": x, "y": y, "features": {"state": state}}
            for (x, y), state in zip(zip(self.coords[0::2], self.coords[1::2]), self.states)
        ]
    else:
        result = [{"x": x, "y": y} for x, y in zip(self.coords[0::2], self.coords[1::2])]
    return result

none() classmethod

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

Returns:

Type Description
KeyPoints

"None" KeyPoints.

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

    Returns:
        "None" KeyPoints.
    """
    return cls(
        id="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        template_id="",
        coords=[0, 0],
        states=["invisible"],
    )

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

Bases: Annotation

A set of 3D keypoints.

Attributes:

Name Type Description
template_id str

id of keypoint template.

coords list[float]

List of 3D coordinates of the keypoints.

states list[str]

Status for each keypoint.

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)

map_back2front_vertices()

Utility function to map back format for KeyPoint3D to front vertices format.

Warn

Not implemented for 3D keypoints.

Source code in pixano/features/schemas/annotations/keypoints.py
def map_back2front_vertices(self) -> list:
    """Utility function to map back format for KeyPoint3D to front vertices format.

    Warn:
        Not implemented for 3D keypoints.
    """
    raise NotImplementedError("Not implemented for 3D keypoints.")

none() classmethod

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

Returns:

Type Description
KeyPoints3D

"None" KeyPoints3D.

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

    Returns:
        "None" KeyPoints3D.
    """
    return cls(
        id="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        template_id="",
        coords=[0, 0, 0],
        states=["visible"],
    )

create_keypoints(template_id, coords, states, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a KeyPoints instance.

Parameters:

Name Type Description Default
template_id str

id of keypoint template.

required
coords list[float]

List of 2D coordinates of the keypoints.

required
states list[str]

Status for each keypoint. ("visible", "invisible", "hidden").

required
id str

Keypoints 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
KeyPoints

The created KeyPoints instance.

Source code in pixano/features/schemas/annotations/keypoints.py
def create_keypoints(
    template_id: str,
    coords: list[float],
    states: list[str],
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
) -> KeyPoints:
    """Create a `KeyPoints` instance.

    Args:
        template_id: id of keypoint template.
        coords: List of 2D coordinates of the keypoints.
        states: Status for each keypoint. ("visible", "invisible", "hidden").
        id: Keypoints ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

    Returns:
        The created `KeyPoints` instance.
    """
    return KeyPoints(
        template_id=template_id,
        coords=coords,
        states=states,
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
    )

create_keypoints3d(template_id, coords, states, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a KeyPoints3D instance.

Parameters:

Name Type Description Default
template_id str

The id of the keypoint template.

required
coords list[float]

The 3D coordinates of the keypoints.

required
states list[Literal['visible', 'invisble', 'hidden']]

The visibility status for each keypoint.

required
id str

Keypoints3D 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
KeyPoints3D

The created KeyPoints3D instance.

Source code in pixano/features/schemas/annotations/keypoints.py
def create_keypoints3d(
    template_id: str,
    coords: list[float],
    states: list[Literal["visible", "invisble", "hidden"]],
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
) -> KeyPoints3D:
    """Create a `KeyPoints3D` instance.

    Args:
        template_id: The id of the keypoint template.
        coords: The 3D coordinates of the keypoints.
        states: The visibility status for each keypoint.
        id: Keypoints3D ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

    Returns:
        The created `KeyPoints3D` instance.
    """
    return KeyPoints3D(
        template_id=template_id,
        coords=coords,
        states=states,
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
    )

is_keypoints(cls, strict=False)

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

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

is_keypoints3d(cls, strict=False)

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

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