from __future__ import annotations
__all__ = [
"Sign",
]
from abc import ABC, abstractmethod
from typing import Callable, Iterable, Optional, Union
import torch
from numpy.typing import NDArray
[docs]
class Sign(ABC):
def __init__(self, sign, *args, **kwargs) -> None:
"""initialize the sign"""
[docs]
@staticmethod
@abstractmethod
def name() -> str:
"""the string code of the sign format"""
[docs]
@abstractmethod
def show(self, **kwargs) -> None:
"""display the sign"""
@abstractmethod
def _from_path(self, path: str):
"""load the sign from a path"""
@abstractmethod
def _from_data(self, sign_data):
"""load the sign from an object"""
[docs]
@classmethod
@abstractmethod
def load(cls, path: str, **kwargs) -> Sign:
"""read the sign from a path"""
[docs]
@classmethod
@abstractmethod
def load_asset(
cls, label: str, archive_name: Optional[str] = None, **kwargs
) -> Sign:
"""load a sign asset from a dataset"""
[docs]
@staticmethod
@abstractmethod
def concatenate(objects: Iterable[Sign]) -> Sign:
"""concatenate multiple signs in time dimension"""
[docs]
@abstractmethod
def numpy(self, *args, **kwargs) -> NDArray:
"""return the sign as a numpy array"""
[docs]
@abstractmethod
def torch(
self,
dtype: Optional[torch.dtype] = None,
device: Union[torch.device, str, None] = None,
) -> torch.Tensor:
"""return the sign as a torch tensor"""
[docs]
@abstractmethod
def save(self, path: str, **kwargs) -> None:
"""save the sign to a path"""