本文整理汇总了Python中absl.flags.DEFINE_integer方法的典型用法代码示例。如果您正苦于以下问题:Python flags.DEFINE_integer方法的具体用法?Python flags.DEFINE_integer怎么用?Python flags.DEFINE_integer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.flags
的用法示例。
在下文中一共展示了flags.DEFINE_integer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: define_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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)
示例2: _define_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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`).
示例3: config_with_absl
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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))
示例4: test_flag_help_in_xml_int_with_bounds
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [as 别名]
def test_flag_help_in_xml_int_with_bounds(self):
flags.DEFINE_integer('nb_iters', 17, 'An integer flag',
lower_bound=5, upper_bound=27,
flag_values=self.fv)
expected_output = (
'<flag>\n'
' <key>yes</key>\n'
' <file>module.name</file>\n'
' <name>nb_iters</name>\n'
' <meaning>An integer flag</meaning>\n'
' <default>17</default>\n'
' <current>17</current>\n'
' <type>int</type>\n'
' <lower_bound>5</lower_bound>\n'
' <upper_bound>27</upper_bound>\n'
'</flag>\n')
self._check_flag_help_in_xml('nb_iters', 'module.name', expected_output,
is_key=True)
示例5: define_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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)
示例6: setUp
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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)
示例7: define_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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)
示例8: DEFINE_integer
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [as 别名]
def DEFINE_integer(
name: str,
default: Optional[int],
help: str,
required: bool = False,
lower_bound: Optional[int] = None,
upper_bound: Optional[int] = None,
validator: Callable[[int], bool] = None,
):
"""Registers a flag whose value must be an integer."""
absl_flags.DEFINE_integer(
name,
default,
help,
module_name=get_calling_module_name(),
lower_bound=lower_bound,
upper_bound=upper_bound,
)
if required:
absl_flags.mark_flag_as_required(name)
if validator:
RegisterFlagValidator(name, validator)
示例9: testReadAndWrite
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [as 别名]
def testReadAndWrite(self):
flag_values = flags.FlagValues()
flags.DEFINE_integer('test_flag', 0, 'Test flag.', flag_values=flag_values)
flag_values([sys.argv[0]])
flag_values_overrides = {}
flag_values_overrides['test_flag'] = 1
self.assertFlagState(flag_values, 0, False)
self.assertEqual(flag_values_overrides['test_flag'], 1)
with flag_util.OverrideFlags(flag_values, flag_values_overrides):
self.assertFlagState(flag_values, 1, True)
self.assertEqual(flag_values_overrides['test_flag'], 1)
self.assertFlagState(flag_values, 0, False)
self.assertEqual(flag_values_overrides['test_flag'], 1)
flag_values.test_flag = 3
self.assertFlagState(flag_values, 3, False)
self.assertEqual(flag_values_overrides['test_flag'], 1)
示例10: DEFINE_integer
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [as 别名]
def DEFINE_integer(name, default, help, lower_bound=None, upper_bound=None): # pylint: disable=invalid-name,redefined-builtin
kwargs = {'lower_bound': lower_bound, 'upper_bound': upper_bound}
param_specs[name] = ParamSpec('integer', default, help, kwargs)
示例11: define_device
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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
示例12: define_distribution
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [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
示例13: DEFINE_integer
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [as 别名]
def DEFINE_integer(self, name, default, *args, **kwargs):
self.add_option(name, default, int, args, kwargs)
示例14: define_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [as 别名]
def define_flags():
"""Define a command line flag for each ParamSpec in _DEFAULT_PARAMS."""
define_flag = {
'boolean': flags.DEFINE_boolean,
'float': flags.DEFINE_float,
'integer': flags.DEFINE_integer,
'string': flags.DEFINE_string,
}
for name, param_spec in six.iteritems(_DEFAULT_PARAMS):
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,
param_spec.description)
flags.declare_key_flag(name)
示例15: define_tpu_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_integer [as 别名]
def define_tpu_flags():
"""Define common flags for TPU."""
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_integer(
'num_cores', default=8, help='Number of TPU cores for training')
flags.DEFINE_string(
'eval_master',
default='',
help='GRPC URL of the eval master. Set to an appropiate value when running '
'on CPU/GPU')
flags.DEFINE_bool('use_tpu', True, 'Use TPUs rather than CPUs')
flags.DEFINE_multi_integer(
'input_partition_dims', [1],
'A list that describes the partition dims for all the tensors.')
flags.DEFINE_integer('iterations_per_loop', 8,
'Number of iterations per TPU training loop')