From 7e3b77933fa43a6db39ab5009786a7ad9869dfeb Mon Sep 17 00:00:00 2001 From: lilei Date: Sat, 10 Jul 2021 17:07:25 +0800 Subject: [PATCH] modify model_zoo bug for config --- .../official/cv/resnet/src/model_utils/config.py | 12 ++++++++---- .../official/cv/resnext/src/model_utils/config.py | 12 ++++++++---- .../official/cv/squeezenet/model_utils/config.py | 15 ++++++++++----- .../official/cv/ssd/src/model_utils/config.py | 15 ++++++++++----- .../official/cv/unet/src/model_utils/config.py | 12 ++++++++---- .../official/cv/unet3d/src/model_utils/config.py | 14 +++++++++----- .../official/nlp/mass/src/model_utils/config.py | 12 ++++++++---- .../official/nlp/textcnn/model_utils/config.py | 12 ++++++++---- .../cv/ssd_ghostnet/src/model_utils/config.py | 15 ++++++++++----- 9 files changed, 79 insertions(+), 40 deletions(-) diff --git a/model_zoo/official/cv/resnet/src/model_utils/config.py b/model_zoo/official/cv/resnet/src/model_utils/config.py index e6faaaefbc5..d8f6518f1ad 100644 --- a/model_zoo/official/cv/resnet/src/model_utils/config.py +++ b/model_zoo/official/cv/resnet/src/model_utils/config.py @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,9 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, \ "../resnet50_cifar10_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) pprint(default) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config) diff --git a/model_zoo/official/cv/resnext/src/model_utils/config.py b/model_zoo/official/cv/resnext/src/model_utils/config.py index 92136db1e0c..a7cd0de8fcb 100644 --- a/model_zoo/official/cv/resnext/src/model_utils/config.py +++ b/model_zoo/official/cv/resnext/src/model_utils/config.py @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,9 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, "../../default_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) pprint(default) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config) diff --git a/model_zoo/official/cv/squeezenet/model_utils/config.py b/model_zoo/official/cv/squeezenet/model_utils/config.py index 5d591e2c50e..66dd05dcfdf 100644 --- a/model_zoo/official/cv/squeezenet/model_utils/config.py +++ b/model_zoo/official/cv/squeezenet/model_utils/config.py @@ -18,7 +18,7 @@ import os import ast import argparse -from pprint import pformat +from pprint import pprint, pformat import yaml _config_path = "./squeezenet_cifar10_config.yaml" @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,8 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, \ "../squeezenet_cifar10_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) + pprint(default) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config) diff --git a/model_zoo/official/cv/ssd/src/model_utils/config.py b/model_zoo/official/cv/ssd/src/model_utils/config.py index eea54c7c5cc..51845d09fcf 100644 --- a/model_zoo/official/cv/ssd/src/model_utils/config.py +++ b/model_zoo/official/cv/ssd/src/model_utils/config.py @@ -18,7 +18,7 @@ import os import ast import argparse -from pprint import pformat +from pprint import pprint, pformat import yaml _config_path = "./ssd300_config.yaml" @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,8 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, \ "../../ssd300_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) + pprint(default) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config) diff --git a/model_zoo/official/cv/unet/src/model_utils/config.py b/model_zoo/official/cv/unet/src/model_utils/config.py index e7bddbf924c..b1107ce4a7f 100644 --- a/model_zoo/official/cv/unet/src/model_utils/config.py +++ b/model_zoo/official/cv/unet/src/model_utils/config.py @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,9 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, "../../unet_simple_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) pprint(default) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config) diff --git a/model_zoo/official/cv/unet3d/src/model_utils/config.py b/model_zoo/official/cv/unet3d/src/model_utils/config.py index 4d022dd3c51..a7cd0de8fcb 100644 --- a/model_zoo/official/cv/unet3d/src/model_utils/config.py +++ b/model_zoo/official/cv/unet3d/src/model_utils/config.py @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,10 +120,10 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, "../../default_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) + pprint(default) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) - pprint(final_config) return Config(final_config) config = get_config() diff --git a/model_zoo/official/nlp/mass/src/model_utils/config.py b/model_zoo/official/nlp/mass/src/model_utils/config.py index 92136db1e0c..a7cd0de8fcb 100644 --- a/model_zoo/official/nlp/mass/src/model_utils/config.py +++ b/model_zoo/official/nlp/mass/src/model_utils/config.py @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,9 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, "../../default_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) pprint(default) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config) diff --git a/model_zoo/official/nlp/textcnn/model_utils/config.py b/model_zoo/official/nlp/textcnn/model_utils/config.py index 31c47f185c0..3a1777d9c8f 100644 --- a/model_zoo/official/nlp/textcnn/model_utils/config.py +++ b/model_zoo/official/nlp/textcnn/model_utils/config.py @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,9 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, "../mr_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) pprint(default) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config) diff --git a/model_zoo/research/cv/ssd_ghostnet/src/model_utils/config.py b/model_zoo/research/cv/ssd_ghostnet/src/model_utils/config.py index fd62bd859dc..a7cd0de8fcb 100644 --- a/model_zoo/research/cv/ssd_ghostnet/src/model_utils/config.py +++ b/model_zoo/research/cv/ssd_ghostnet/src/model_utils/config.py @@ -18,7 +18,7 @@ import os import ast import argparse -from pprint import pformat +from pprint import pprint, pformat import yaml _config_path = "./default_config.yaml" @@ -83,14 +83,18 @@ def parse_yaml(yaml_path): if len(cfgs) == 1: cfg_helper = {} cfg = cfgs[0] + cfg_choices = {} elif len(cfgs) == 2: cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs else: - raise ValueError("At most 2 docs (config and help description for help) are supported in config yaml") + raise ValueError("At most 3 docs (config description for help, choices) are supported in config yaml") print(cfg_helper) except: raise ValueError("Failed to parse yaml") - return cfg, cfg_helper + return cfg, cfg_helper, cfg_choices def merge(args, cfg): @@ -116,8 +120,9 @@ def get_config(): parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, "../../default_config.yaml"), help="Config file path") path_args, _ = parser.parse_known_args() - default, helper = parse_yaml(path_args.config_path) - args = parse_cli_to_yaml(parser, default, helper, path_args.config_path) + default, helper, choices = parse_yaml(path_args.config_path) + pprint(default) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) final_config = merge(args, default) return Config(final_config)