-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathconfig.py
44 lines (38 loc) · 1.12 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
"""
* Copyright (C) 2019 Zhonghui You
* If you are using this code in your research, please cite the paper:
* Gate Decorator: Global Filter Pruning Method for Accelerating Deep Convolutional Neural Networks, in NeurIPS 2019.
"""
import argparse
import json
from utils import dotdict
def make_as_dotdict(obj):
if type(obj) is dict:
obj = dotdict(obj)
for key in obj:
if type(obj[key]) is dict:
obj[key] = make_as_dotdict(obj[key])
return obj
def parse():
print('Parsing config file...')
parser = argparse.ArgumentParser(description="config")
parser.add_argument(
"--config",
type=str,
default="configs/base.json",
help="Configuration file to use"
)
cli_args = parser.parse_args()
with open(cli_args.config) as fp:
config = make_as_dotdict(json.loads(fp.read()))
print(json.dumps(config, indent=4, sort_keys=True))
return config
cfg = None
if cfg is None:
try:
cfg = parse()
except:
print('** Assert in demo mode. **')
def parse_from_dict(d):
global cfg
cfg = make_as_dotdict(d)