-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_config2.py
52 lines (42 loc) · 1.71 KB
/
print_config2.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
# Copyright (c) OpenMMLab. All rights reserved.
# Copyright (C) University of Waikato, Hamilton, NZ
import argparse
from mmcv import Config, DictAction
from mmseg.apis import init_segmentor
def parse_args():
parser = argparse.ArgumentParser(description='Print the whole config')
parser.add_argument('--config', help='config file path')
parser.add_argument(
'--graph', action='store_true', help='print the models graph')
parser.add_argument(
'--cfg-options',
nargs='+',
action=DictAction,
help='override some settings in the used config, the key-value pair '
'in xxx=yyy format will be merged into config file. If the value to '
'be overwritten is a list, it should be like key="[a,b]" or key=a,b '
'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" '
'Note that the quotation marks are necessary and that no white space '
'is allowed.')
parser.add_argument(
'--output_config', required=True, help='where to store the generated config')
parser.add_argument(
'--output_graph', required=False, help='where to store the graph (requires --graph)')
args = parser.parse_args()
return args
def main():
args = parse_args()
cfg = Config.fromfile(args.config)
if args.cfg_options is not None:
cfg.merge_from_dict(args.cfg_options)
print(f'Config:\n{cfg.pretty_text}')
# dump config
cfg.dump(args.output_config)
# dump models graph
if args.graph:
model = init_segmentor(args.config, device='cpu')
print(f'Model graph:\n{str(model)}')
with open(args.output_graph, 'w') as f:
f.writelines(str(model))
if __name__ == '__main__':
main()