You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

print_config.py 1.9 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import argparse
  3. import warnings
  4. from mmcv import Config, DictAction
  5. def parse_args():
  6. parser = argparse.ArgumentParser(description='Print the whole config')
  7. parser.add_argument('config', help='config file path')
  8. parser.add_argument(
  9. '--options',
  10. nargs='+',
  11. action=DictAction,
  12. help='override some settings in the used config, the key-value pair '
  13. 'in xxx=yyy format will be merged into config file (deprecate), '
  14. 'change to --cfg-options instead.')
  15. parser.add_argument(
  16. '--cfg-options',
  17. nargs='+',
  18. action=DictAction,
  19. help='override some settings in the used config, the key-value pair '
  20. 'in xxx=yyy format will be merged into config file. If the value to '
  21. 'be overwritten is a list, it should be like key="[a,b]" or key=a,b '
  22. 'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" '
  23. 'Note that the quotation marks are necessary and that no white space '
  24. 'is allowed.')
  25. args = parser.parse_args()
  26. if args.options and args.cfg_options:
  27. raise ValueError(
  28. '--options and --cfg-options cannot be both '
  29. 'specified, --options is deprecated in favor of --cfg-options')
  30. if args.options:
  31. warnings.warn('--options is deprecated in favor of --cfg-options')
  32. args.cfg_options = args.options
  33. return args
  34. def main():
  35. args = parse_args()
  36. cfg = Config.fromfile(args.config)
  37. if args.cfg_options is not None:
  38. cfg.merge_from_dict(args.cfg_options)
  39. # import modules from string list.
  40. if cfg.get('custom_imports', None):
  41. from mmcv.utils import import_modules_from_strings
  42. import_modules_from_strings(**cfg['custom_imports'])
  43. print(f'Config:\n{cfg.pretty_text}')
  44. if __name__ == '__main__':
  45. main()

No Description

Contributors (1)