File size: 960 Bytes
2cd560a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import yaml
from easydict import EasyDict
def merge_new_config(config, new_config):
if '_BASE_CONFIG_' in new_config:
with open(new_config['_BASE_CONFIG_'], 'r') as f:
try:
yaml_config = yaml.safe_load(f, Loader=yaml.FullLoader)
except:
yaml_config = yaml.safe_load(f)
config.update(EasyDict(yaml_config))
for key, val in new_config.items():
if not isinstance(val, dict):
config[key] = val
continue
if key not in config:
config[key] = EasyDict()
merge_new_config(config[key], val)
return config
def cfg_from_yaml_file(cfg_file, config):
with open(cfg_file, 'r') as f:
try:
new_config = yaml.safe_load(f, Loader=yaml.FullLoader)
except:
new_config = yaml.safe_load(f)
merge_new_config(config=config, new_config=new_config)
return config
cfg = EasyDict()
|