DefaultScope — mmengine 0.10.7 documentation (original) (raw)
class mmengine.registry.DefaultScope(name, scope_name)[source]¶
Scope of current task used to reset the current registry, which can be accessed globally.
Consider the case of resetting the current Registry
bydefault_scope
in the internal module which cannot access runner directly, it is difficult to get the default_scope
defined inRunner
. However, if Runner
created DefaultScope
instance by given default_scope
, the internal module can getdefault_scope
by DefaultScope.get_current_instance
everywhere.
Parameters:
Examples
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()[source]¶
Get latest created default scope.
Since default_scope is an optional argument for Registry.build
.get_current_instance
should return None
if there is noDefaultScope
created.
Examples
default_scope = DefaultScope.get_current_instance()
There is no
DefaultScope
created yet,
get_current_instance
returnNone
.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
Returns:
Return None If there has not beenDefaultScope
instance created yet, otherwise return the latest created DefaultScope instance.
Return type:
Optional[DefaultScope]
classmethod overwrite_default_scope(scope_name)[source]¶
Overwrite the current default scope with scope_name
Parameters:
scope_name (str | None) –
Return type:
Returns: str: Get current scope.