-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbase.py
More file actions
53 lines (41 loc) · 1.3 KB
/
base.py
File metadata and controls
53 lines (41 loc) · 1.3 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
"""Abstract base class for inference modules."""
from abc import ABC, abstractmethod
from typing import Any, Dict
class BaseModule(ABC):
"""Abstract base class for all inference modules.
All modules must implement load(), unload(), and infer() methods
to provide a consistent interface.
"""
def __init__(self):
self._loaded = False
self._model = None
@abstractmethod
def load(self, **kwargs) -> None:
"""Load the model into memory.
Args:
**kwargs: Model-specific configuration (paths, etc.)
"""
pass
@abstractmethod
def unload(self) -> None:
"""Unload the model and free resources."""
pass
@abstractmethod
def infer(self, **kwargs) -> Any:
"""Run inference on input data.
Args:
**kwargs: Model-specific input parameters
Returns:
Model-specific output
"""
pass
@property
def is_loaded(self) -> bool:
"""Check if the model is loaded."""
return self._loaded
def get_status(self) -> Dict[str, Any]:
"""Get module status information."""
return {
"loaded": self._loaded,
"model_type": self.__class__.__name__,
}