-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry.py
More file actions
50 lines (41 loc) · 1.36 KB
/
registry.py
File metadata and controls
50 lines (41 loc) · 1.36 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
"""This module implements a metaclass for automatic registration of
classes."""
from typing import TypeVar
from luxonis_ml.data.loaders import LuxonisLoader
from luxonis_ml.utils.registry import Registry
import luxonis_eval as lxeval
ENGINES_REGISTRY: Registry[type["lxeval.BaseEngine"]] = Registry(
name="engines"
)
DATALOADERS_REGISTRY: Registry[type["lxeval.BaseEvalLoader"]] = Registry(
name="dataloaders"
)
METRICS_REGISTRY: Registry[type["lxeval.BaseMetric"]] = Registry(
name="metrics"
)
VISUALIZERS_REGISTRY: Registry[type["lxeval.BaseVisualizer"]] = Registry(
name="visualizers"
)
PARSERS_REGISTRY: Registry[type["lxeval.BaseParser"]] = Registry(
name="parsers"
)
DATALOADERS_REGISTRY.register(module=LuxonisLoader) # type: ignore
T = TypeVar("T")
def from_registry(registry: Registry[type[T]], key: str, *args, **kwargs) -> T:
"""Get an instance of the class registered under the given key.
Parameters
----------
registry : Registry[type[T]]
Registry to get the class from.
key : str
Key to get the class for.
*args : Any
Positional arguments to pass to the class constructor.
**kwargs : Any
Keyword arguments to pass to the class constructor.
Returns
-------
T
Instance of the class registered under the given key.
"""
return registry.get(key)(*args, **kwargs)