4from typing
import Dict, Optional
9 The registry that provides name -> object mapping, to support third-party
10 users' custom modules.
11 To create a registry (e.g. a backbone registry):
12 .. code-block:: python
13 BACKBONE_REGISTRY = Registry('BACKBONE')
14 To register an object:
15 .. code-block:: python
16 @BACKBONE_REGISTRY.register()
20 .. code-block:: python
21 BACKBONE_REGISTRY.register(MyBackbone)
27 name (str): the name of this registry
29 self._name: str = name
30 self._obj_map: Dict[str, object] = {}
34 name
not in self._obj_map
35 ),
"An object named '{}' was already registered in '{}' registry!".format(
38 self._obj_map[name] = obj
40 def register(self, obj: object =
None) -> Optional[object]:
42 Register the given object under the the name `obj.__name__`.
43 Can be used as either a decorator or not. See docstring of this class for usage.
47 def deco(func_or_class: object) -> object:
48 name = func_or_class.__name__
58 def get(self, name: str) -> object:
59 ret = self._obj_map.
get(name)
62 "No object named '{}' found in '{}' registry!".format(
object get(self, str name)
None _do_register(self, str name, object obj)
Optional[object] register(self, object obj=None)
None __init__(self, str name)