Files

38 lines
986 B
Python

"""Base interface for all pipelines."""
from abc import ABC, abstractmethod
import torch
from pydantic import BaseModel
class Requirements(BaseModel):
"""Requirements for pipeline configuration."""
input_size: int
class Pipeline(ABC):
"""Abstract base class for all pipelines."""
@abstractmethod
def prepare(self, should_prepare: bool = False, **kwargs) -> Requirements | None:
"""Prepare the pipeline and get requirements for the next processing chunk."""
pass
@abstractmethod
def __call__(
self, input: torch.Tensor | list[torch.Tensor] | None = None, **kwargs
) -> torch.Tensor:
"""
Process a chunk of video frames.
Args:
input: A tensor in BCTHW format OR a list of frame tensors in THWC format (in [0, 255] range), or None
**kwargs: Additional parameters
Returns:
A processed chunk tensor in THWC format and [0, 1] range
"""
pass