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
Registrybydefault_scopein the internal module which cannot access runner directly, it is difficult to get thedefault_scopedefined inRunner. However, ifRunnercreatedDefaultScopeinstance by givendefault_scope, the internal module can getdefault_scopebyDefaultScope.get_current_instanceeverywhere.示例
>>> 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_instanceshould returnNoneif there is noDefaultScopecreated.示例
>>> 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
DefaultScopeinstance created yet, otherwise return the latest created DefaultScope instance.- 返回类型:
Optional[DefaultScope]