diff --git a/ppcls/utils/config.py b/ppcls/utils/config.py index 3d30cab706319c1c8f85318d028cf35ba282e12e..01669f3bbc5470f6b10b571b3c73cd4af08995df 100644 --- a/ppcls/utils/config.py +++ b/ppcls/utils/config.py @@ -14,13 +14,12 @@ import os import yaml + from ppcls.utils import check from ppcls.utils import logger __all__ = ['get_config'] -CONFIG_SECS = ['ARCHITECTURE', 'TRAIN', 'VALID', 'OPTIMIZER', 'LEARNING_RATE'] - class AttrDict(dict): def __getattr__(self, key): @@ -63,9 +62,8 @@ def print_dict(d, delimiter=0): Recursively visualize a dict and indenting acrrording by the relationship of keys. """ - for k, v in d.items(): - if k in CONFIG_SECS: - logger.info("-" * 60) + for k, v in sorted(d.items()): + if k.istitle(): logger.info("-" * 60) if isinstance(v, dict): logger.info("{}{} : ".format(delimiter * " ", k)) @@ -77,27 +75,23 @@ def print_dict(d, delimiter=0): else: logger.info("{}{} : {}".format(delimiter * " ", k, v)) - if k in CONFIG_SECS: - logger.info("-" * 60) + if k.istitle(): logger.info("-" * 60) -def print_config(config): +def print_config(config, show=True): """ visualize configs Arguments: config: configs """ + if not show: return copyright = "PaddleClas is powered by PaddlePaddle" ad = "https://github.com/PaddlePaddle/PaddleClas" - logger.info("\n" * 2) - logger.info(copyright) - logger.info(ad) - + logger.info("\n\n{}\n{}".format(copyright, ad)) print_dict(config) - logger.info("-" * 60) @@ -193,11 +187,9 @@ def get_config(fname, overrides=[], show=True): assert os.path.exists(fname), \ ('config file({}) is not exist'.format(fname)) config = parse_config(fname) - if show: - print_config(config) + print_config(config, show) if len(overrides) > 0: override_config(config, overrides) - if show: - print_config(config) + print_config(config, show) check_config(config) return config