Get the registry record. Args: key: The class name in string format. Returns: class: The corresponding class. Example: >>> from deeplabcut.pose_estimation_pytorch.registry import Registry >>> registry = Registry("models")
(self, key)
| 165 | return self._children |
| 166 | |
| 167 | def get(self, key): |
| 168 | """Get the registry record. |
| 169 | |
| 170 | Args: |
| 171 | key: The class name in string format. |
| 172 | |
| 173 | Returns: |
| 174 | class: The corresponding class. |
| 175 | |
| 176 | Example: |
| 177 | >>> from deeplabcut.pose_estimation_pytorch.registry import Registry |
| 178 | >>> registry = Registry("models") |
| 179 | >>> class Model: |
| 180 | >>> pass |
| 181 | >>> registry.register_module(Model, "Model") |
| 182 | >>> assert registry.get("Model") == Model |
| 183 | """ |
| 184 | scope, real_key = self.split_scope_key(key) |
| 185 | if scope is None or scope == self._scope: |
| 186 | # get from self |
| 187 | if real_key in self._module_dict: |
| 188 | return self._module_dict[real_key] |
| 189 | else: |
| 190 | # get from self._children |
| 191 | if scope in self._children: |
| 192 | return self._children[scope].get(real_key) |
| 193 | else: |
| 194 | # goto root |
| 195 | parent = self.parent |
| 196 | while parent.parent is not None: |
| 197 | parent = parent.parent |
| 198 | return parent.get(key) |
| 199 | |
| 200 | def build(self, *args, **kwargs): |
| 201 | """Builds an instance from the registry. |