[Enhance] Replace print with print_log for those functions called by runner (#686)

* Replace print with print_log for those function called by runner

* minor refine

* Fix as comment
This commit is contained in:
Mashiro 2022-11-08 16:35:36 +08:00 committed by GitHub
parent ed20a9cba5
commit 5e60402dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View File

@ -18,6 +18,7 @@ from addict import Dict
from yapf.yapflib.yapf_api import FormatCode
from mmengine.fileio import dump, load
from mmengine.logging import print_log
from mmengine.utils import (check_file_exist, get_installed_path,
import_modules_from_strings, is_installed)
from .utils import (RemoveAssignFromAST, _get_external_cfg_base_path,
@ -86,7 +87,9 @@ def add_args(parser: ArgumentParser,
parser.add_argument(
'--' + prefix + k, type=type(next(iter(v))), nargs='+')
else:
print(f'cannot parse key {prefix + k} of type {type(v)}')
print_log(
f'cannot parse key {prefix + k} of type {type(v)}',
logger='current')
return parser

View File

@ -13,6 +13,7 @@ from typing import Callable, List, Optional, Sequence, Union
from torch.optim import Optimizer
from mmengine.logging import print_log
from mmengine.optim import OptimWrapper
from mmengine.registry import PARAM_SCHEDULERS
@ -172,8 +173,9 @@ class _ParamScheduler:
value (float): The parameter value.
"""
if is_verbose:
print('Adjusting parameter value'
' of group {} to {:.4e}.'.format(group, value))
print_log(
f'Adjusting parameter value of group {group} to {value:.4e}.',
logger='current')
def step(self):
"""Adjusts the parameter value of each parameter group based on the

View File

@ -4,6 +4,7 @@ import os.path as osp
from typing import Optional
from mmengine.fileio import dump
from mmengine.logging import print_log
from . import root
from .registry import Registry
@ -35,8 +36,10 @@ def traverse_registry_tree(registry: Registry, verbose: bool = True) -> list:
else:
registry_info[folder] = [name]
if verbose:
print(f"Find {num_modules} modules in {scope}'s "
f"'{_registry.name}' registry ")
print_log(
f"Find {num_modules} modules in {scope}'s "
f"'{_registry.name}' registry ",
logger='current')
modules_info.append(registry_info)
else:
return
@ -80,9 +83,10 @@ def count_registered_modules(save_path: Optional[str] = None,
scan_date=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
registries=registries_info)
if verbose:
print('Finish registry analysis, got: ', scan_data)
print_log(
f'Finish registry analysis, got: {scan_data}', logger='current')
if save_path is not None:
json_path = osp.join(save_path, 'modules_statistic_results.json')
dump(scan_data, json_path, indent=2)
print(f'Result has been saved to {json_path}')
print_log(f'Result has been saved to {json_path}', logger='current')
return scan_data