classpulse-edge / core /base_module.py
thegoatcc's picture
Upload ClassPulse Edge codebase, Dockerfile, and model weights
af70f62 verified
Raw History Blame Contribute Delete
1.68 kB
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Optional
from core.config_manager import ConfigManager
from core.state import FrameContext
class BaseModelWrapper(ABC):
"""Uniform adapter contract for HailoRT (.hef), ONNX (.onnx), MediaPipe (.task), or PC mocks."""
@abstractmethod
def load(self) -> None:
"""Load pre-cached offline model weights into NPU/CPU memory."""
@abstractmethod
def process(self, context: FrameContext) -> FrameContext:
"""Run inference and enrich FrameContext in-place."""
def close(self) -> None:
"""Release hardware/NPU handles cleanly on shutdown."""
class PipelineModule(ABC):
"""Plug-and-play Lego brick governed by ConfigManager Zero-Deletion Toggling."""
def __init__(
self,
name: str,
config: ConfigManager,
branch: Optional[str] = None,
wrapper: Optional[BaseModelWrapper] = None,
) -> None:
self.name = name
self.config = config
self.branch = branch
self.wrapper = wrapper
def initialize(self) -> None:
if self.wrapper is not None:
self.wrapper.load()
def execute(self, context: FrameContext) -> FrameContext:
if not self.config.is_active(self.name, self.branch):
return context
return self.run(context)
@abstractmethod
def run(self, context: FrameContext) -> FrameContext:
"""Module-specific business logic operating on FrameContext."""
def shutdown(self) -> None:
if self.wrapper is not None:
self.wrapper.close()