-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
31 lines (25 loc) · 856 Bytes
/
utils.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
import argparse
import importlib
import omegaconf.dictconfig
from Register import Registers
from runners.BBDMRunner import BBDMRunner
def dict2namespace(config):
namespace = argparse.Namespace()
for key, value in config.items():
if isinstance(value, dict) or isinstance(value, omegaconf.dictconfig.DictConfig):
new_value = dict2namespace(value)
else:
new_value = value
setattr(namespace, key, new_value)
return namespace
def namespace2dict(config):
conf_dict = {}
for key, value in vars(config).items():
if isinstance(value, argparse.Namespace):
conf_dict[key] = namespace2dict(value)
else:
conf_dict[key] = value
return conf_dict
def get_runner(runner_name, config):
runner = Registers.runners[runner_name](config)
return runner