DECO / utils /get_cfg.py
ac5113's picture
added files
99a05f0
raw
history blame
613 Bytes
from yacs.config import CfgNode
_VALID_TYPES = {tuple, list, str, int, float, bool}
def convert_to_dict(cfg_node, key_list=[]):
""" Convert a config node to dictionary """
if not isinstance(cfg_node, CfgNode):
if type(cfg_node) not in _VALID_TYPES:
print("Key {} with value {} is not a valid type; valid types: {}".format(
".".join(key_list), type(cfg_node), _VALID_TYPES), )
return cfg_node
else:
cfg_dict = dict(cfg_node)
for k, v in cfg_dict.items():
cfg_dict[k] = convert_to_dict(v, key_list + [k])
return cfg_dict