From a093181ce04f9ae376d98bdd352dbb46e6786b48 Mon Sep 17 00:00:00 2001 From: dreamerlin <528557675@qq.com> Date: Sat, 26 Sep 2020 15:23:58 +0800 Subject: [PATCH 1/4] add customized imports --- tools/test.py | 13 +++++++++++-- tools/train.py | 10 +++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/test.py b/tools/test.py index 62e7ece693..c7c3c7f0b5 100644 --- a/tools/test.py +++ b/tools/test.py @@ -2,8 +2,8 @@ import os import os.path as osp -import mmcv import torch +from mmcv import Config, DictAction from mmcv.cnn import fuse_conv_bn from mmcv.parallel import MMDataParallel, MMDistributedDataParallel from mmcv.runner import get_dist_info, init_dist, load_checkpoint @@ -41,6 +41,12 @@ def parse_args(): help='tmp directory used for collecting results from multiple ' 'workers, available when gpu-collect is not specified') parser.add_argument('--options', nargs='+', help='custom options') + 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.') parser.add_argument( '--average-clips', choices=['score', 'prob', None], @@ -72,7 +78,10 @@ def merge_configs(cfg1, cfg2): def main(): args = parse_args() - cfg = mmcv.Config.fromfile(args.config) + cfg = Config.fromfile(args.config) + + if args.cfg_options is not None: + cfg.merge_from_dict(args.cfg_options) # Load output_config from cfg output_config = cfg.get('output_config', {}) diff --git a/tools/train.py b/tools/train.py index 9ed8359a78..7c48050719 100644 --- a/tools/train.py +++ b/tools/train.py @@ -7,7 +7,7 @@ import mmcv import torch -from mmcv import Config +from mmcv import Config, DictAction from mmcv.runner import init_dist, set_random_seed from mmcv.utils import get_git_hash @@ -45,6 +45,12 @@ def parse_args(): '--deterministic', action='store_true', help='whether to set deterministic options for CUDNN backend.') + 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.') parser.add_argument( '--launcher', choices=['none', 'pytorch', 'slurm', 'mpi'], @@ -62,6 +68,8 @@ def main(): args = parse_args() cfg = Config.fromfile(args.config) + if args.cfg_options is not None: + cfg.merge_from_dict(args.cfg_options) # set cudnn_benchmark if cfg.get('cudnn_benchmark', False): torch.backends.cudnn.benchmark = True From c888b2396638fb74dd11a55bceb3f02c7433bb2e Mon Sep 17 00:00:00 2001 From: dreamerlin <528557675@qq.com> Date: Thu, 15 Oct 2020 23:32:35 +0800 Subject: [PATCH 2/4] minor --- tools/test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/test.py b/tools/test.py index c7c3c7f0b5..aed36dd93d 100644 --- a/tools/test.py +++ b/tools/test.py @@ -2,6 +2,7 @@ import os import os.path as osp +import mmcv import torch from mmcv import Config, DictAction from mmcv.cnn import fuse_conv_bn From 4c2dbe2a713518591b997927433744eda0cf633b Mon Sep 17 00:00:00 2001 From: dreamerlin <528557675@qq.com> Date: Fri, 16 Oct 2020 20:49:23 +0800 Subject: [PATCH 3/4] update example --- tools/test.py | 7 ++++--- tools/train.py | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/test.py b/tools/test.py index aed36dd93d..ffa2093139 100644 --- a/tools/test.py +++ b/tools/test.py @@ -46,8 +46,10 @@ def parse_args(): '--cfg-options', nargs='+', action=DictAction, + default={}, help='override some settings in the used config, the key-value pair ' - 'in xxx=yyy format will be merged into config file.') + 'in xxx=yyy format will be merged into config file. For example, ' + "'--cfg-options model.backbone.depth=18 model.backbone.with_cp=True'") parser.add_argument( '--average-clips', choices=['score', 'prob', None], @@ -81,8 +83,7 @@ def main(): cfg = Config.fromfile(args.config) - if args.cfg_options is not None: - cfg.merge_from_dict(args.cfg_options) + cfg.merge_from_dict(args.cfg_options) # Load output_config from cfg output_config = cfg.get('output_config', {}) diff --git a/tools/train.py b/tools/train.py index 7c48050719..c853ac3823 100644 --- a/tools/train.py +++ b/tools/train.py @@ -49,8 +49,10 @@ def parse_args(): '--cfg-options', nargs='+', action=DictAction, + default={}, help='override some settings in the used config, the key-value pair ' - 'in xxx=yyy format will be merged into config file.') + 'in xxx=yyy format will be merged into config file. For example, ' + "'--cfg-options model.backbone.depth=18 model.backbone.with_cp=True'") parser.add_argument( '--launcher', choices=['none', 'pytorch', 'slurm', 'mpi'], @@ -68,8 +70,9 @@ def main(): args = parse_args() cfg = Config.fromfile(args.config) - if args.cfg_options is not None: - cfg.merge_from_dict(args.cfg_options) + + cfg.merge_from_dict(args.cfg_options) + # set cudnn_benchmark if cfg.get('cudnn_benchmark', False): torch.backends.cudnn.benchmark = True From 577ef504a9ee8e870c8ec1199a8d4289f2ed90f8 Mon Sep 17 00:00:00 2001 From: dreamerlin <528557675@qq.com> Date: Fri, 16 Oct 2020 20:53:06 +0800 Subject: [PATCH 4/4] update changelog --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index d0fe20a249..ce5152f752 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,7 @@ **Improvements** - Set default values of 'average_clips' in each config file so that there is no need to set it explicitly during testing in most cases ([#232](https://github.com/open-mmlab/mmaction2/pull/232)) +- Add `cfg-options` in arguments to override some settings in the used config for convenience ([#212](https://github.com/open-mmlab/mmaction2/pull/212)) **Bug Fixes** - Fix the potential bug for default value in dataset_setting ([#245](https://github.com/open-mmlab/mmaction2/pull/245))