-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_engine.py
More file actions
66 lines (54 loc) · 1.73 KB
/
base_engine.py
File metadata and controls
66 lines (54 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from abc import ABC, abstractmethod
from typing import Any
import numpy as np
from luxonis_ml.utils.registry import AutoRegisterMeta
from luxonis_eval.registry import ENGINES_REGISTRY
class BaseEngine(
ABC,
metaclass=AutoRegisterMeta,
registry=ENGINES_REGISTRY,
register=False,
):
"""Abstract base class for inference engines."""
def __init__(self, model_path: str, **kwargs: Any) -> None:
"""Initialize the engine.
Parameters
----------
model_path : str
Path to the model file.
**kwargs : Any
Engine basic configuration.
"""
self.model_path = model_path
self.width, self.height = self.get_input_shape()
if self.width is None or self.height is None:
raise ValueError(
"Invalid input shape: width and height must be defined."
)
self.platform_name = self.get_platform_name()
if self.platform_name is None:
raise ValueError("Platform name must be defined.")
@abstractmethod
def setup(self) -> None:
"""Initialize backend resources."""
...
@abstractmethod
def get_input_shape(self) -> tuple[int, int]:
"""Get the input shape (width, height) from the loaded model."""
...
@abstractmethod
def get_platform_name(self) -> str:
"""Get the platform name."""
...
@abstractmethod
def infer_once(self, img: np.ndarray) -> Any:
"""Run inference on a single image."""
...
@abstractmethod
def vis_frame(self) -> np.ndarray:
"""Return a visualization frame."""
...
@abstractmethod
def teardown(self) -> None:
"""Release backend resources."""
...