Skip to content

MMEngine

OpenMMLab Foundational Library for Training Deep Learning Models

Config 읽기

from mmengine.config import Config

cfg = Config.fromfile('pspnet.py')
print(cfg.model)

Modify config through script arguments

In the training script and the testing script, we support the script argument --cfg-options, it may help users override some settings in the used config, the key-value pair in xxx=yyy format will be merged into config file.

For example, this is a simplified script demo_script.py:

import argparse

from mmengine.config import Config, DictAction

def parse_args():
    parser = argparse.ArgumentParser(description='Script Example')
    parser.add_argument('config', help='train config file path')
    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.')
    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(cfg)

if __name__ == '__main__':
    main()

See also

Favorite site