当前位置: 首页>>代码示例>>Python>>正文


Python configargparse.YAMLConfigFileParser方法代码示例

本文整理汇总了Python中configargparse.YAMLConfigFileParser方法的典型用法代码示例。如果您正苦于以下问题:Python configargparse.YAMLConfigFileParser方法的具体用法?Python configargparse.YAMLConfigFileParser怎么用?Python configargparse.YAMLConfigFileParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configargparse的用法示例。


在下文中一共展示了configargparse.YAMLConfigFileParser方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_args

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def parse_args():
    parser = configargparse.ArgumentParser(
        description='preprocess.py',
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        formatter_class=configargparse.ArgumentDefaultsHelpFormatter)

    opts.config_opts(parser)
    opts.add_md_help_argument(parser)
    opts.preprocess_opts(parser)

    opt = parser.parse_args()
    torch.manual_seed(opt.seed)

    check_existing_pt_files(opt)

    return opt 
开发者ID:lizekang,项目名称:ITDD,代码行数:18,代码来源:preprocess.py

示例2: save_args_to_file

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def save_args_to_file(file_name, **kwargs):
    """
    Saves `**kwargs` to a file.

    Args:
        file_name (str): The name of the file where the args should
            be saved in.

    """
    options_to_save = {
        k.replace('_', '-'): v for k, v in kwargs.items() if v is not None
    }

    content = configargparse.YAMLConfigFileParser().serialize(options_to_save)
    Path(file_name).write_text(content)
    logging.debug('Saved current options to config file: {}'.format(file_name)) 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:18,代码来源:utils.py

示例3: run

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def run(options, extra_options):
    config_parser = configargparse.YAMLConfigFileParser()
    config_options = config_parser.parse(Path(options.config).read_text())
    meta, fixed_options = split_options(config_options)

    # Run for each combination of arguments
    fixed_args = [options.model_name] + extra_options
    if options.experiment_name:
        fixed_args += parser.convert_item_to_command_line_arg(
            None, 'experiment-name', options.experiment_name
        )

    meta_keys = meta.keys()
    meta_values = meta.values()
    for values in itertools.product(*meta_values):
        assert len(meta_keys) == len(values)
        run_args = []
        for key, value in zip(meta_keys, values):
            action = get_action(key)
            run_args.extend(
                parser.convert_item_to_command_line_arg(action, key, str(value))
            )
        full_args = fixed_args + run_args + fixed_options
        train.main(full_args) 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:26,代码来源:search.py

示例4: __init__

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def __init__(
        self, name, pipeline_parser, pipeline_config_key, options_fn=None
    ):
        self.name = name
        self._pipeline_parser = pipeline_parser
        self._pipeline_config_key = pipeline_config_key.replace('-', '_')

        self._parser = configargparse.get_argument_parser(
            self.name,
            prog='kiwi {}'.format(self.name),
            add_help=False,
            config_file_parser_class=configargparse.YAMLConfigFileParser,
            ignore_unknown_config_file_keys=False,
        )

        self._parser.add(
            '--config',
            required=False,
            is_config_file=True,
            type=PathType(exists=True),
            help='Load config file from path',
        )

        if options_fn is not None:
            options_fn(self._parser) 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:27,代码来源:better_argparse.py

示例5: parse

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def parse():
	"""
	adds and parses arguments / hyperparameters
	"""
	default = os.path.join(current(), data + ".yml")
	p = configargparse.ArgParser(config_file_parser_class = YAMLConfigFileParser, default_config_files=[default])
	p.add('-c', '--my-config', is_config_file=True, help='config file path')
	p.add('--data', type=str, default=data, help='data name (coauthorship/cocitation)')
	p.add('--dataset', type=str, default=dataset, help='dataset name (e.g.: cora/dblp/acm for coauthorship, cora/citeseer/pubmed for cocitation)')
	p.add('--mediators', type=bool, default=mediators, help='True for Laplacian with mediators, False for Laplacian without mediators')
	p.add('--fast', type=bool, default=fast, help='faster version of HyperGCN (True)')
	p.add('--split', type=int, default=split, help='train-test split used for the dataset')
	p.add('--depth', type=int, default=depth, help='number of hidden layers')
	p.add('--dropout', type=float, default=dropout, help='dropout probability for GCN hidden layer')
	p.add('--rate', type=float, default=rate, help='learning rate')
	p.add('--decay', type=float, default=decay, help='weight decay')
	p.add('--epochs', type=int, default=epochs, help='number of epochs to train')
	p.add('--gpu', type=int, default=gpu, help='gpu number to use')
	p.add('--cuda', type=bool, default=cuda, help='cuda for gpu')
	p.add('--seed', type=int, default=seed, help='seed for randomness')
	p.add('-f') # for jupyter default
	return p.parse_args() 
开发者ID:malllabiisc,项目名称:HyperGCN,代码行数:24,代码来源:config.py

示例6: testYAMLConfigFileParser_Basic

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def testYAMLConfigFileParser_Basic(self):
        try:
            import yaml
        except:
            logging.warning("WARNING: PyYAML not installed. "
                            "Couldn't test YAMLConfigFileParser")
            return

        p = configargparse.YAMLConfigFileParser()
        self.assertGreater(len(p.get_syntax_description()), 0)

        input_config_str = StringIO("""a: '3'\n""")
        parsed_obj = p.parse(input_config_str)
        output_config_str = p.serialize(dict(parsed_obj))

        self.assertEqual(input_config_str.getvalue(), output_config_str)

        self.assertDictEqual(parsed_obj, {'a': '3'}) 
开发者ID:bw2,项目名称:ConfigArgParse,代码行数:20,代码来源:test_configargparse.py

示例7: get_parser

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def get_parser(cls, name, **kwargs):
        if name in cls._parsers:
            return cls._parsers[name]
        parser = configargparse.get_argument_parser(
            name,
            prog='... {}'.format(name),
            config_file_parser_class=configargparse.YAMLConfigFileParser,
            ignore_unknown_config_file_keys=True,
            **kwargs,
        )
        cls._parsers[name] = parser
        return parser 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:14,代码来源:better_argparse.py

示例8: get_parser

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def get_parser():
    parser = configargparse.ArgumentParser(
        description='generate RST from argparse options',
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        formatter_class=configargparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('src', type=str, nargs='+',
                        help='source python files that contain get_parser() func')
    return parser


# parser 
开发者ID:espnet,项目名称:espnet,代码行数:13,代码来源:argparse2rst.py

示例9: __init__

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def __init__(
            self,
            config_file_parser_class=cfargparse.YAMLConfigFileParser,
            formatter_class=cfargparse.ArgumentDefaultsHelpFormatter,
            **kwargs):
        super(ArgumentParser, self).__init__(
            config_file_parser_class=config_file_parser_class,
            formatter_class=formatter_class,
            **kwargs) 
开发者ID:harvardnlp,项目名称:encoder-agnostic-adaptation,代码行数:11,代码来源:parse.py

示例10: _get_parser

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def _get_parser():
    parser = configargparse.ArgumentParser(
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        description="OpenNMT-py REST Server")
    parser.add_argument("--ip", type=str, default="0.0.0.0")
    parser.add_argument("--port", type=int, default="5000")
    parser.add_argument("--url_root", type=str, default="/translator")
    parser.add_argument("--debug", "-d", action="store_true")
    parser.add_argument("--config", "-c", type=str,
                        default="./available_models/conf.json")
    return parser 
开发者ID:OpenNMT,项目名称:OpenNMT-py,代码行数:13,代码来源:server.py

示例11: testYAMLConfigFileParser_All

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def testYAMLConfigFileParser_All(self):
        try:
            import yaml
        except:
            logging.warning("WARNING: PyYAML not installed. "
                            "Couldn't test YAMLConfigFileParser")
            return

        p = configargparse.YAMLConfigFileParser()

        # test the all syntax case
        config_lines = [
            "a: '3'",
            "list_arg:",
            "- 1",
            "- 2",
            "- 3",
        ]

        # test parse
        input_config_str = StringIO("\n".join(config_lines)+"\n")
        parsed_obj = p.parse(input_config_str)

        # test serialize
        output_config_str = p.serialize(parsed_obj)
        self.assertEqual(input_config_str.getvalue(), output_config_str)

        self.assertDictEqual(parsed_obj, {'a': '3', 'list_arg': [1,2,3]})



################################################################################
# since configargparse should work as a drop-in replacement for argparse
# in all situations, run argparse unittests on configargparse by modifying
# their source code to use configargparse.ArgumentParser 
开发者ID:bw2,项目名称:ConfigArgParse,代码行数:37,代码来源:test_configargparse.py

示例12: get_parser

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import YAMLConfigFileParser [as 别名]
def get_parser():
    """Get parser of decoding arguments."""
    parser = configargparse.ArgumentParser(
        description='Synthesize speech from text using a TTS model on one CPU',
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        formatter_class=configargparse.ArgumentDefaultsHelpFormatter)
    # general configuration
    parser.add('--config', is_config_file=True, help='config file path')
    parser.add('--config2', is_config_file=True,
               help='second config file path that overwrites the settings in `--config`.')
    parser.add('--config3', is_config_file=True,
               help='third config file path that overwrites the settings in `--config` and `--config2`.')

    parser.add_argument('--ngpu', default=0, type=int,
                        help='Number of GPUs')
    parser.add_argument('--backend', default='pytorch', type=str,
                        choices=['chainer', 'pytorch'],
                        help='Backend library')
    parser.add_argument('--debugmode', default=1, type=int,
                        help='Debugmode')
    parser.add_argument('--seed', default=1, type=int,
                        help='Random seed')
    parser.add_argument('--out', type=str, required=True,
                        help='Output filename')
    parser.add_argument('--verbose', '-V', default=0, type=int,
                        help='Verbose option')
    parser.add_argument('--preprocess-conf', type=str, default=None,
                        help='The configuration file for the pre-processing')
    # task related
    parser.add_argument('--json', type=str, required=True,
                        help='Filename of train label data (json)')
    parser.add_argument('--model', type=str, required=True,
                        help='Model file parameters to read')
    parser.add_argument('--model-conf', type=str, default=None,
                        help='Model config file')
    # decoding related
    parser.add_argument('--maxlenratio', type=float, default=5,
                        help='Maximum length ratio in decoding')
    parser.add_argument('--minlenratio', type=float, default=0,
                        help='Minimum length ratio in decoding')
    parser.add_argument('--threshold', type=float, default=0.5,
                        help='Threshold value in decoding')
    parser.add_argument('--use-att-constraint', type=strtobool, default=False,
                        help='Whether to use the attention constraint')
    parser.add_argument('--backward-window', type=int, default=1,
                        help='Backward window size in the attention constraint')
    parser.add_argument('--forward-window', type=int, default=3,
                        help='Forward window size in the attention constraint')
    # save related
    parser.add_argument('--save-durations', default=False, type=strtobool,
                        help='Whether to save durations converted from attentions')
    parser.add_argument('--save-focus-rates', default=False, type=strtobool,
                        help='Whether to save focus rates of attentions')
    return parser 
开发者ID:DigitalPhonetics,项目名称:adviser,代码行数:56,代码来源:tts_decode.py


注:本文中的configargparse.YAMLConfigFileParser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。