Shortcuts

DefaultScope

class mmengine.registry.DefaultScope(name, scope_name)[源代码]

Scope of current task used to reset the current registry, which can be accessed globally.

Consider the case of resetting the current Registry by default_scope in the internal module which cannot access runner directly, it is difficult to get the default_scope defined in Runner. However, if Runner created DefaultScope instance by given default_scope, the internal module can get default_scope by DefaultScope.get_current_instance everywhere.

参数
  • name (str) – Name of default scope for global access.

  • scope_name (str) – Scope of current task.

实际案例

>>> from mmengine.model import MODELS
>>> # Define default scope in runner.
>>> DefaultScope.get_instance('task', scope_name='mmdet')
>>> # Get default scope globally.
>>> scope_name = DefaultScope.get_instance('task').scope_name
classmethod get_current_instance()[源代码]

Get latest created default scope.

Since default_scope is an optional argument for Registry.build. get_current_instance should return None if there is no DefaultScope created.

实际案例

>>> default_scope = DefaultScope.get_current_instance()
>>> # There is no `DefaultScope` created yet,
>>> # `get_current_instance` return `None`.
>>> default_scope = DefaultScope.get_instance(
>>>     'instance_name', scope_name='mmengine')
>>> default_scope.scope_name
mmengine
>>> default_scope = DefaultScope.get_current_instance()
>>> default_scope.scope_name
mmengine
返回

Return None If there has not been DefaultScope instance created yet, otherwise return the latest created DefaultScope instance.

返回类型

Optional[DefaultScope]

classmethod overwrite_default_scope(scope_name)[源代码]

overwrite the current default scope with scope_name

参数

scope_name (Optional[str]) –

返回类型

Generator

property scope_name: str

Returns: str: Get current scope.

Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.