deeplabcut.pose_estimation_pytorch.registry
Classes:
| Name | Description |
|---|---|
Registry |
A registry to map strings to classes or functions. Registered objects could be |
Functions:
| Name | Description |
|---|---|
build_from_cfg |
Builds a module from the configuration dictionary when it represents a class |
Registry
A registry to map strings to classes or functions. Registered objects could be built from the registry. Meanwhile, registered functions could be called from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Registry name. |
required | |
|
Builds function to construct an instance from
the Registry. If neither |
None
|
|
|
Parent registry. The class registered in children's registry could be built from the parent. Default: None. |
None
|
|
|
The scope of the registry. It is the key to search for children's registry. If not specified, scope will be the name of the package where the class is defined, e.g. mmdet, mmcls, mmseg. Default: None. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Registry name. |
|
module_dict |
The dictionary containing registered modules. |
|
children |
The dictionary containing children registries. |
|
scope |
The scope of the registry. |
Methods:
| Name | Description |
|---|---|
build |
Builds an instance from the registry. |
deprecated_register_module |
Decorator to register a class in the registry. |
get |
Get the registry record. |
register_module |
Register a module. |
split_scope_key |
Split scope and key. |
Source code in deeplabcut/pose_estimation_pytorch/registry.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
build
Builds an instance from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Arguments passed to the build function. |
()
|
|
|
Keyword arguments passed to the build function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
The constructed object. |
Example
from deeplabcut.pose_estimation_pytorch.registry import Registry, build_from_cfg class Model: def init(self, param): self.param = param cfg = {"type": "Model", "param": 10} registry = Registry("models") registry.register_module(Model) obj = registry.build(cfg, param=20) assert isinstance(obj, Model) assert obj.param == 20
Source code in deeplabcut/pose_estimation_pytorch/registry.py
deprecated_register_module
Decorator to register a class in the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
The class to be registered. |
None
|
|
|
Whether to override an existing class with the same name. Default: False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
type |
The input class. |
Example
from deeplabcut.pose_estimation_pytorch.registry import Registry registry = Registry("models") @registry.deprecated_register_module() class Model: pass assert registry.get("Model") == Model
Source code in deeplabcut/pose_estimation_pytorch/registry.py
get
Get the registry record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
The class name in string format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
class |
The corresponding class. |
Example
from deeplabcut.pose_estimation_pytorch.registry import Registry registry = Registry("models") class Model: pass registry.register_module(Model, "Model") assert registry.get("Model") == Model
Source code in deeplabcut/pose_estimation_pytorch/registry.py
register_module
Register a module.
A record will be added to self._module_dict, whose key is the class
name or the specified name, and value is the class itself.
It can be used as a decorator or a normal function.
Args:
name: The module name to be registered. If not
specified, the class name will be used.
force: Whether to override an existing class with
the same name. Default: False.
module: Module class or function to be registered.
Source code in deeplabcut/pose_estimation_pytorch/registry.py
split_scope_key
staticmethod
Split scope and key.
The first scope will be split from key.
Examples:
>>> Registry.split_scope_key('mmdet.ResNet')
'mmdet', 'ResNet'
>>> Registry.split_scope_key('ResNet')
None, 'ResNet'
Return:
tuple[str | None, str]: The former element is the first scope of
the key, which can be None. The latter is the remaining key.
Source code in deeplabcut/pose_estimation_pytorch/registry.py
build_from_cfg
Builds a module from the configuration dictionary when it represents a class configuration, or call a function from the configuration dictionary when it represents a function configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
Configuration dictionary. It should at least contain the key "type". |
required |
|
Registry
|
The registry to search the type from. |
required |
|
dict | None
|
Default initialization arguments. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The constructed object. |
Example
from deeplabcut.pose_estimation_pytorch.registry import Registry, build_from_cfg class Model: def init(self, param): self.param = param cfg = {"type": "Model", "param": 10} registry = Registry("models") registry.register_module(Model) obj = build_from_cfg(cfg, registry) assert isinstance(obj, Model) assert obj.param == 10