[Enhance]: remove warning in vis_backend (#273)

* fix visbackend warning

* fix
pull/280/head
Haian Huang(深度眸) 2022-06-06 14:02:15 +08:00 committed by GitHub
parent 70c4ea191f
commit 94c7c3be2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import torch
from mmengine.config import Config
from mmengine.fileio import dump
from mmengine.logging import MMLogger
from mmengine.registry import VISBACKENDS
from mmengine.utils import TORCH_VERSION
@ -40,11 +41,12 @@ def force_init_env(old_func: Callable) -> Any:
# `_env_initialized` is False, call `_init_env` and set
# `_env_initialized` to True
if not getattr(obj, '_env_initialized', False):
warnings.warn('Attribute `_env_initialized` is not defined in '
f'{type(obj)} or `type(obj)._env_initialized is '
'False, `_init_env` will be called and '
f'{type(obj)}._env_initialized will be set to '
'True')
logger = MMLogger.get_current_instance()
logger.debug('Attribute `_env_initialized` is not defined in '
f'{type(obj)} or `{type(obj)}._env_initialized is '
'False, `_init_env` will be called and '
f'{type(obj)}._env_initialized will be set to '
'True')
obj._init_env() # type: ignore
obj._env_initialized = True # type: ignore