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


Python flags.DEFINE_string方法代码示例

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


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

示例1: define_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def define_flags(specs=None):
  """Define a command line flag for each ParamSpec in flags.param_specs."""
  specs = specs or param_specs
  define_flag = {
      'boolean': absl_flags.DEFINE_boolean,
      'float': absl_flags.DEFINE_float,
      'integer': absl_flags.DEFINE_integer,
      'string': absl_flags.DEFINE_string,
      'enum': absl_flags.DEFINE_enum,
      'list': absl_flags.DEFINE_list
  }
  for name, param_spec in six.iteritems(specs):
    if param_spec.flag_type not in define_flag:
      raise ValueError('Unknown flag_type %s' % param_spec.flag_type)
    else:
      define_flag[param_spec.flag_type](name, param_spec.default_value,
                                        help=param_spec.description,
                                        **param_spec.kwargs) 
开发者ID:tensorflow,项目名称:benchmarks,代码行数:20,代码来源:flags.py

示例2: _define_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def _define_flags(options):
  for option in _filter_options(options):
    name, type_, default_ = option[:3]
    if type_ == 'boolean':
      flags.DEFINE_boolean(name, default_, '')
    elif type_ == 'integer':
      flags.DEFINE_integer(name, default_, '')
    elif type_ == 'float':
      flags.DEFINE_float(name, default_, '')
    elif type_ == 'string':
      flags.DEFINE_string(name, default_, '')
    elif type_ == 'list_of_ints':
      flags.DEFINE_string(name, default_, '')
    else:
      assert 'Unexpected option type %s' % type_


# Define command-line flags for all options (unless `internal`). 
开发者ID:deepmind,项目名称:lamb,代码行数:20,代码来源:lamb_flags.py

示例3: define_compute_bleu_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def define_compute_bleu_flags():
  """Add flags for computing BLEU score."""
  flags.DEFINE_string(
      name="translation", default=None,
      help=flags_core.help_wrap("File containing translated text."))
  flags.mark_flag_as_required("translation")

  flags.DEFINE_string(
      name="reference", default=None,
      help=flags_core.help_wrap("File containing reference translation."))
  flags.mark_flag_as_required("reference")

  flags.DEFINE_enum(
      name="bleu_variant", short_name="bv", default="both",
      enum_values=["both", "uncased", "cased"], case_sensitive=False,
      help=flags_core.help_wrap(
          "Specify one or more BLEU variants to calculate. Variants: \"cased\""
          ", \"uncased\", or \"both\".")) 
开发者ID:IntelAI,项目名称:models,代码行数:20,代码来源:compute_bleu.py

示例4: initialize_common_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def initialize_common_flags():
  """Define the common flags across models."""
  define_common_hparams_flags()

  flags_core.define_device(tpu=True)
  flags_core.define_base(
      num_gpu=True, model_dir=False, data_dir=False, batch_size=False)
  flags_core.define_distribution(worker_hosts=True, task_index=True)
  flags_core.define_performance(all_reduce_alg=True, num_packs=True)

  # Reset the default value of num_gpus to zero.
  FLAGS.num_gpus = 0

  flags.DEFINE_string(
      'strategy_type', 'mirrored', 'Type of distribute strategy.'
      'One of mirrored, tpu and multiworker.') 
开发者ID:IntelAI,项目名称:models,代码行数:18,代码来源:hyperparams_flags.py

示例5: config_with_absl

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def config_with_absl(self):
    # Run this before calling `app.run(main)` etc
    import absl.flags as absl_FLAGS
    from absl import app, flags as absl_flags

    self.use_absl = True
    self.absl_flags = absl_flags
    absl_defs = { bool: absl_flags.DEFINE_bool,
                  int:  absl_flags.DEFINE_integer,
                  str:  absl_flags.DEFINE_string,
                  'enum': absl_flags.DEFINE_enum }

    for name, val in self.values.items():
      flag_type, meta_args, meta_kwargs = self.meta[name]
      absl_defs[flag_type](name, val, *meta_args, **meta_kwargs)

    app.call_after_init(lambda: self.complete_absl_config(absl_flags)) 
开发者ID:google,项目名称:trax,代码行数:19,代码来源:config.py

示例6: record_new_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def record_new_flags() -> Iterator[List[str]]:
  """A context manager that returns all flags created in it's scope.

  This is useful to define all of the flags which should be considered
  hyperparameters of the training run, without needing to repeat them.

  Example usage:
  ```python
  with record_new_flags() as hparam_flags:
      flags.DEFINE_string('exp_name', 'name', 'Unique name for the experiment.')
  ```

  Check `research/emnist/run_experiment.py` for more details about the usage.

  Yields:
    A list of all newly created flags.
  """
  old_flags = set(iter(flags.FLAGS))
  new_flags = []
  yield new_flags
  new_flags.extend([f for f in flags.FLAGS if f not in old_flags]) 
开发者ID:tensorflow,项目名称:federated,代码行数:23,代码来源:utils_impl.py

示例7: define_common_tpu_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def define_common_tpu_flags():
  """Define the flags related to TPU's."""
  flags.DEFINE_string(
      'tpu', default=None,
      help='The Cloud TPU to use for training. This should be either the name '
      'used when creating the Cloud TPU, or a grpc://ip.address.of.tpu:8470 '
      'url.')

  flags.DEFINE_string(
      'gcp_project', default=None,
      help='Project name for the Cloud TPU-enabled project. If not specified, we '
      'will attempt to automatically detect the GCE project from metadata.')

  flags.DEFINE_string(
      'tpu_zone', default=None,
      help='GCE zone where the Cloud TPU is located in. If not specified, we '
      'will attempt to automatically detect the GCE project from metadata.')

  flags.DEFINE_string(
      'eval_master', default='',
      help='GRPC URL of the eval master. Set to an appropiate value when running '
      'on CPU/GPU.') 
开发者ID:artyompal,项目名称:tpu_models,代码行数:24,代码来源:common_tpu_flags.py

示例8: define_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def define_flags(flag_values=FLAGS):
  """Defines some flags.

  Args:
    flag_values: The FlagValues object we want to register the flags
      with.
  """
  # The 'tmod_bar_' prefix (short for 'test_module_bar') ensures there
  # is no name clash with the existing flags.
  flags.DEFINE_boolean('tmod_bar_x', True, 'Boolean flag.',
                       flag_values=flag_values)
  flags.DEFINE_string('tmod_bar_y', 'default', 'String flag.',
                      flag_values=flag_values)
  flags.DEFINE_boolean('tmod_bar_z', False,
                       'Another boolean flag from module bar.',
                       flag_values=flag_values)
  flags.DEFINE_integer('tmod_bar_t', 4, 'Sample int flag.',
                       flag_values=flag_values)
  flags.DEFINE_integer('tmod_bar_u', 5, 'Sample int flag.',
                       flag_values=flag_values)
  flags.DEFINE_integer('tmod_bar_v', 6, 'Sample int flag.',
                       flag_values=flag_values) 
开发者ID:abseil,项目名称:abseil-py,代码行数:24,代码来源:module_bar.py

示例9: setUp

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def setUp(self):
    self._absl_flags = flags.FlagValues()
    flags.DEFINE_bool(
        'absl_bool', None, 'help for --absl_bool.',
        short_name='b', flag_values=self._absl_flags)
    # Add a boolean flag that starts with "no", to verify it can correctly
    # handle the "no" prefixes in boolean flags.
    flags.DEFINE_bool(
        'notice', None, 'help for --notice.',
        flag_values=self._absl_flags)
    flags.DEFINE_string(
        'absl_string', 'default', 'help for --absl_string=%.',
        short_name='s', flag_values=self._absl_flags)
    flags.DEFINE_integer(
        'absl_integer', 1, 'help for --absl_integer.',
        flag_values=self._absl_flags)
    flags.DEFINE_float(
        'absl_float', 1, 'help for --absl_integer.',
        flag_values=self._absl_flags)
    flags.DEFINE_enum(
        'absl_enum', 'apple', ['apple', 'orange'], 'help for --absl_enum.',
        flag_values=self._absl_flags) 
开发者ID:abseil,项目名称:abseil-py,代码行数:24,代码来源:argparse_flags_test.py

示例10: test_helpfull_message

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def test_helpfull_message(self):
    flags.DEFINE_string(
        'non_main_module_flag', 'default', 'help',
        module_name='other.module', flag_values=self._absl_flags)
    parser = argparse_flags.ArgumentParser(
        inherited_absl_flags=self._absl_flags)
    with self.assertRaises(SystemExit),\
        mock.patch.object(sys, 'stdout', new=six.StringIO()) as mock_stdout:
      parser.parse_args(['--helpfull'])
    stdout_message = mock_stdout.getvalue()
    logging.info('captured stdout message:\n%s', stdout_message)
    self.assertIn('--non_main_module_flag', stdout_message)
    self.assertIn('other.module', stdout_message)
    # Make sure the main module is not included.
    self.assertNotIn(sys.argv[0], stdout_message)
    # Special flags defined in absl.flags.
    self.assertIn('absl.flags:', stdout_message)
    self.assertIn('--flagfile', stdout_message)
    self.assertIn('--undefok', stdout_message) 
开发者ID:abseil,项目名称:abseil-py,代码行数:21,代码来源:argparse_flags_test.py

示例11: define_flags

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def define_flags():
  """Define a command line flag for each ParamSpec in flags.param_specs."""
  define_flag = {
      'boolean': absl_flags.DEFINE_boolean,
      'float': absl_flags.DEFINE_float,
      'integer': absl_flags.DEFINE_integer,
      'string': absl_flags.DEFINE_string,
      'enum': absl_flags.DEFINE_enum,
      'list': absl_flags.DEFINE_list
  }
  for name, param_spec in six.iteritems(param_specs):
    if param_spec.flag_type not in define_flag:
      raise ValueError('Unknown flag_type %s' % param_spec.flag_type)
    else:
      define_flag[param_spec.flag_type](name, param_spec.default_value,
                                        help=param_spec.description,
                                        **param_spec.kwargs) 
开发者ID:HewlettPackard,项目名称:dlcookbook-dlbs,代码行数:19,代码来源:flags.py

示例12: DEFINE_string

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def DEFINE_string(name, default, help):  # pylint: disable=invalid-name,redefined-builtin
  param_specs[name] = ParamSpec('string', default, help, {}) 
开发者ID:tensorflow,项目名称:benchmarks,代码行数:4,代码来源:flags.py

示例13: define_device

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def define_device(tpu=True):
  """Register device specific flags.
  Args:
    tpu: Create flags to specify TPU operation.
  Returns:
    A list of flags for core.py to marks as key flags.
  """

  key_flags = []

  if tpu:
    flags.DEFINE_string(
        name="tpu", default=None,
        help=help_wrap(
            "The Cloud TPU to use for training. This should be either the name "
            "used when creating the Cloud TPU, or a "
            "grpc://ip.address.of.tpu:8470 url. Passing `local` will use the"
            "CPU of the local instance instead. (Good for debugging.)"))
    key_flags.append("tpu")

    flags.DEFINE_string(
        name="tpu_zone", default=None,
        help=help_wrap(
            "[Optional] GCE zone where the Cloud TPU is located in. If not "
            "specified, we will attempt to automatically detect the GCE "
            "project from metadata."))

    flags.DEFINE_string(
        name="tpu_gcp_project", default=None,
        help=help_wrap(
            "[Optional] Project name for the Cloud TPU-enabled project. If not "
            "specified, we will attempt to automatically detect the GCE "
            "project from metadata."))

    flags.DEFINE_integer(name="num_tpu_shards", default=8,
                         help=help_wrap("Number of shards (TPU chips)."))

  return key_flags 
开发者ID:IntelAI,项目名称:models,代码行数:40,代码来源:_device.py

示例14: define_distribution

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def define_distribution(worker_hosts=True, task_index=True):
  """Register distributed execution flags.

  Args:
    worker_hosts: Create a flag for specifying comma-separated list of workers.
    task_index: Create a flag for specifying index of task.

  Returns:
    A list of flags for core.py to marks as key flags.
  """
  key_flags = []

  if worker_hosts:
    flags.DEFINE_string(
        name='worker_hosts', default=None,
        help=help_wrap(
            'Comma-separated list of worker ip:port pairs for running '
            'multi-worker models with DistributionStrategy.  The user would '
            'start the program on each host with identical value for this '
            'flag.'))

  if task_index:
    flags.DEFINE_integer(
        name='task_index', default=-1,
        help=help_wrap('If multi-worker training, the task_index of this '
                       'worker.'))

  return key_flags 
开发者ID:IntelAI,项目名称:models,代码行数:30,代码来源:_distribution.py

示例15: DEFINE_string

# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_string [as 别名]
def DEFINE_string(self, name, default, *args, **kwargs):
    self.add_option(name, default, str, args, kwargs) 
开发者ID:google,项目名称:trax,代码行数:4,代码来源:config.py


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