-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.py
54 lines (40 loc) · 1.25 KB
/
config.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import pprint
import logging
import yaml
from easydict import EasyDict as edict
import default_config
cfg = default_config.cfg
def _merge_a_into_b(a, b):
"""Merge config dictionary a into config dictionary b, clobbering the
options in b whenever they are also specified in a.
"""
if type(a) is not edict:
return
for k, v in a.items():
# a must specify keys that are in b
#if k not in b:
# raise KeyError('{} is not a valid config key'.format(k))
# recursively merge dicts
if type(v) is edict:
try:
_merge_a_into_b(a[k], b[k])
except:
print('Error under config key: {}'.format(k))
raise
else:
b[k] = v
def cfg_from_file(filename):
"""Load a config from file filename and merge it into the default options.
"""
with open(filename, 'r') as f:
yaml_cfg = edict(yaml.load(f))
_merge_a_into_b(yaml_cfg, cfg)
return cfg
def load_config(filename = "pose_cfg.yaml"):
if 'POSE_PARAM_PATH' in os.environ:
filename = os.environ['POSE_PARAM_PATH'] + '/' + filename
cfg = cfg_from_file(filename)
return cfg
if __name__ == "__main__":
print(load_config())