Skip to content

Commit

Permalink
[Feature] save config file in print_config.py (#9276)
Browse files Browse the repository at this point in the history
* Add feature to save config file in print_config.py

Add feature to print_config.py to save configuration files

* Update print_config.py

* Update print_config.py

* Update tools/misc/print_config.py

Co-authored-by: BigDong <yudongwang1226@gmail.com>

* Format

* Update print_config.py

* add suffix check

* Update tools/misc/print_config.py

Co-authored-by: RangiLyu <lyuchqi@gmail.com>

Co-authored-by: BigDong <yudongwang1226@gmail.com>
Co-authored-by: BIGWangYuDong <yudongwang@tju.edu.cn>
Co-authored-by: RangiLyu <lyuchqi@gmail.com>
  • Loading branch information
4 people committed Nov 22, 2022
1 parent f8e8212 commit e139990
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/misc/print_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os

from mmengine import Config, DictAction

Expand All @@ -9,6 +10,10 @@
def parse_args():
parser = argparse.ArgumentParser(description='Print the whole config')
parser.add_argument('config', help='config file path')
parser.add_argument(
'--save-path',
default=None,
help='save path of whole config, suffixed with .py, .json or .yml')
parser.add_argument(
'--cfg-options',
nargs='+',
Expand Down Expand Up @@ -39,6 +44,17 @@ def main():
cfg.merge_from_dict(args.cfg_options)
print(f'Config:\n{cfg.pretty_text}')

if args.save_path is not None:
save_path = args.save_path

suffix = os.path.splitext(save_path)[-1]
assert suffix in ['.py', '.json', '.yml']

if not os.path.exists(os.path.split(save_path)[0]):
os.makedirs(os.path.split(save_path)[0])
cfg.dump(save_path)
print(f'Config saving at {save_path}')


if __name__ == '__main__':
main()

0 comments on commit e139990

Please sign in to comment.