mirror of
https://github.com/open-mmlab/mmengine.git
synced 2025-06-03 21:54:44 +08:00
[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:
parent
ed20a9cba5
commit
5e60402dca
@ -18,6 +18,7 @@ from addict import Dict
|
|||||||
from yapf.yapflib.yapf_api import FormatCode
|
from yapf.yapflib.yapf_api import FormatCode
|
||||||
|
|
||||||
from mmengine.fileio import dump, load
|
from mmengine.fileio import dump, load
|
||||||
|
from mmengine.logging import print_log
|
||||||
from mmengine.utils import (check_file_exist, get_installed_path,
|
from mmengine.utils import (check_file_exist, get_installed_path,
|
||||||
import_modules_from_strings, is_installed)
|
import_modules_from_strings, is_installed)
|
||||||
from .utils import (RemoveAssignFromAST, _get_external_cfg_base_path,
|
from .utils import (RemoveAssignFromAST, _get_external_cfg_base_path,
|
||||||
@ -86,7 +87,9 @@ def add_args(parser: ArgumentParser,
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--' + prefix + k, type=type(next(iter(v))), nargs='+')
|
'--' + prefix + k, type=type(next(iter(v))), nargs='+')
|
||||||
else:
|
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
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ from typing import Callable, List, Optional, Sequence, Union
|
|||||||
|
|
||||||
from torch.optim import Optimizer
|
from torch.optim import Optimizer
|
||||||
|
|
||||||
|
from mmengine.logging import print_log
|
||||||
from mmengine.optim import OptimWrapper
|
from mmengine.optim import OptimWrapper
|
||||||
from mmengine.registry import PARAM_SCHEDULERS
|
from mmengine.registry import PARAM_SCHEDULERS
|
||||||
|
|
||||||
@ -172,8 +173,9 @@ class _ParamScheduler:
|
|||||||
value (float): The parameter value.
|
value (float): The parameter value.
|
||||||
"""
|
"""
|
||||||
if is_verbose:
|
if is_verbose:
|
||||||
print('Adjusting parameter value'
|
print_log(
|
||||||
' of group {} to {:.4e}.'.format(group, value))
|
f'Adjusting parameter value of group {group} to {value:.4e}.',
|
||||||
|
logger='current')
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
"""Adjusts the parameter value of each parameter group based on the
|
"""Adjusts the parameter value of each parameter group based on the
|
||||||
|
@ -4,6 +4,7 @@ import os.path as osp
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from mmengine.fileio import dump
|
from mmengine.fileio import dump
|
||||||
|
from mmengine.logging import print_log
|
||||||
from . import root
|
from . import root
|
||||||
from .registry import Registry
|
from .registry import Registry
|
||||||
|
|
||||||
@ -35,8 +36,10 @@ def traverse_registry_tree(registry: Registry, verbose: bool = True) -> list:
|
|||||||
else:
|
else:
|
||||||
registry_info[folder] = [name]
|
registry_info[folder] = [name]
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Find {num_modules} modules in {scope}'s "
|
print_log(
|
||||||
f"'{_registry.name}' registry ")
|
f"Find {num_modules} modules in {scope}'s "
|
||||||
|
f"'{_registry.name}' registry ",
|
||||||
|
logger='current')
|
||||||
modules_info.append(registry_info)
|
modules_info.append(registry_info)
|
||||||
else:
|
else:
|
||||||
return
|
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'),
|
scan_date=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
registries=registries_info)
|
registries=registries_info)
|
||||||
if verbose:
|
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:
|
if save_path is not None:
|
||||||
json_path = osp.join(save_path, 'modules_statistic_results.json')
|
json_path = osp.join(save_path, 'modules_statistic_results.json')
|
||||||
dump(scan_data, json_path, indent=2)
|
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
|
return scan_data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user