Diff of /tools/print_config.py [000000] .. [4e96d3]

Switch to unified view

a b/tools/print_config.py
1
# Copyright (c) OpenMMLab. All rights reserved.
2
import argparse
3
import warnings
4
5
from mmcv import Config, DictAction
6
7
from mmseg.apis import init_segmentor
8
9
10
def parse_args():
11
    parser = argparse.ArgumentParser(description='Print the whole config')
12
    parser.add_argument('config', help='config file path')
13
    parser.add_argument(
14
        '--graph', action='store_true', help='print the models graph')
15
    parser.add_argument(
16
        '--options',
17
        nargs='+',
18
        action=DictAction,
19
        help="--options is deprecated in favor of --cfg_options' and it will "
20
        'not be supported in version v0.22.0. Override some settings in the '
21
        'used config, the key-value pair in xxx=yyy format will be merged '
22
        'into config file. If the value to be overwritten is a list, it '
23
        'should be like key="[a,b]" or key=a,b It also allows nested '
24
        'list/tuple values, e.g. key="[(a,b),(c,d)]" Note that the quotation '
25
        'marks are necessary and that no white space is allowed.')
26
    parser.add_argument(
27
        '--cfg-options',
28
        nargs='+',
29
        action=DictAction,
30
        help='override some settings in the used config, the key-value pair '
31
        'in xxx=yyy format will be merged into config file. If the value to '
32
        'be overwritten is a list, it should be like key="[a,b]" or key=a,b '
33
        'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" '
34
        'Note that the quotation marks are necessary and that no white space '
35
        'is allowed.')
36
    args = parser.parse_args()
37
38
    if args.options and args.cfg_options:
39
        raise ValueError(
40
            '--options and --cfg-options cannot be both '
41
            'specified, --options is deprecated in favor of --cfg-options. '
42
            '--options will not be supported in version v0.22.0.')
43
    if args.options:
44
        warnings.warn('--options is deprecated in favor of --cfg-options, '
45
                      '--options will not be supported in version v0.22.0.')
46
        args.cfg_options = args.options
47
48
    return args
49
50
51
def main():
52
    args = parse_args()
53
54
    cfg = Config.fromfile(args.config)
55
    if args.cfg_options is not None:
56
        cfg.merge_from_dict(args.cfg_options)
57
    print(f'Config:\n{cfg.pretty_text}')
58
    # dump config
59
    cfg.dump('example.py')
60
    # dump models graph
61
    if args.graph:
62
        model = init_segmentor(args.config, device='cpu')
63
        print(f'Model graph:\n{str(model)}')
64
        with open('example-graph.txt', 'w') as f:
65
            f.writelines(str(model))
66
67
68
if __name__ == '__main__':
69
    main()