本文整理汇总了Python中absl.flags.DEFINE_multi_integer方法的典型用法代码示例。如果您正苦于以下问题:Python flags.DEFINE_multi_integer方法的具体用法?Python flags.DEFINE_multi_integer怎么用?Python flags.DEFINE_multi_integer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.flags
的用法示例。
在下文中一共展示了flags.DEFINE_multi_integer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multi_numerical_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_multi_integer [as 别名]
def test_multi_numerical_flags(self):
"""Test multi_int and multi_float flags."""
int_defaults = [77, 88]
flags.DEFINE_multi_integer('m_int', int_defaults,
'integer option that can occur multiple times',
short_name='mi')
self.assertListEqual(FLAGS.get_flag_value('m_int', None), int_defaults)
argv = ('./program', '--m_int=-99', '--mi=101')
FLAGS(argv)
self.assertListEqual(FLAGS.get_flag_value('m_int', None), [-99, 101])
float_defaults = [2.2, 3]
flags.DEFINE_multi_float('m_float', float_defaults,
'float option that can occur multiple times',
short_name='mf')
for (expected, actual) in zip(
float_defaults, FLAGS.get_flag_value('m_float', None)):
self.assertAlmostEqual(expected, actual)
argv = ('./program', '--m_float=-17', '--mf=2.78e9')
FLAGS(argv)
expected_floats = [-17.0, 2.78e9]
for (expected, actual) in zip(
expected_floats, FLAGS.get_flag_value('m_float', None)):
self.assertAlmostEqual(expected, actual)
示例2: test_multi_numerical_with_tuples
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_multi_integer [as 别名]
def test_multi_numerical_with_tuples(self):
"""Verify multi_int/float accept tuples as default values."""
flags.DEFINE_multi_integer(
'm_int_tuple',
(77, 88),
'integer option that can occur multiple times',
short_name='mi_tuple')
self.assertListEqual(FLAGS.get_flag_value('m_int_tuple', None), [77, 88])
dict_with_float_keys = {2.2: 'hello', 3: 'happy'}
float_defaults = dict_with_float_keys.keys()
flags.DEFINE_multi_float(
'm_float_tuple',
float_defaults,
'float option that can occur multiple times',
short_name='mf_tuple')
for (expected, actual) in zip(float_defaults,
FLAGS.get_flag_value('m_float_tuple', None)):
self.assertAlmostEqual(expected, actual)
示例3: define_tpu_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_multi_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')
示例4: test_single_value_default
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_multi_integer [as 别名]
def test_single_value_default(self):
"""Test multi_int and multi_float flags with a single default value."""
int_default = 77
flags.DEFINE_multi_integer('m_int1', int_default,
'integer option that can occur multiple times')
self.assertListEqual(FLAGS.get_flag_value('m_int1', None), [int_default])
float_default = 2.2
flags.DEFINE_multi_float('m_float1', float_default,
'float option that can occur multiple times')
actual = FLAGS.get_flag_value('m_float1', None)
self.assertEqual(1, len(actual))
self.assertAlmostEqual(actual[0], float_default)
示例5: test_bad_multi_numerical_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_multi_integer [as 别名]
def test_bad_multi_numerical_flags(self):
"""Test multi_int and multi_float flags with non-parseable values."""
# Test non-parseable defaults.
self.assertRaisesRegex(
flags.IllegalFlagValueError,
r"flag --m_int2=abc: invalid literal for int\(\) with base 10: 'abc'",
flags.DEFINE_multi_integer, 'm_int2', ['abc'], 'desc')
self.assertRaisesRegex(
flags.IllegalFlagValueError,
r'flag --m_float2=abc: '
r'(invalid literal for float\(\)|could not convert string to float): '
r"'?abc'?",
flags.DEFINE_multi_float, 'm_float2', ['abc'], 'desc')
# Test non-parseable command line values.
flags.DEFINE_multi_integer('m_int2', '77',
'integer option that can occur multiple times')
argv = ('./program', '--m_int2=def')
self.assertRaisesRegex(
flags.IllegalFlagValueError,
r"flag --m_int2=def: invalid literal for int\(\) with base 10: 'def'",
FLAGS, argv)
flags.DEFINE_multi_float('m_float2', 2.2,
'float option that can occur multiple times')
argv = ('./program', '--m_float2=def')
self.assertRaisesRegex(
flags.IllegalFlagValueError,
r'flag --m_float2=def: '
r'(invalid literal for float\(\)|could not convert string to float): '
r"'?def'?",
FLAGS, argv)
示例6: test_flag_help_in_xml_multi_int
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_multi_integer [as 别名]
def test_flag_help_in_xml_multi_int(self):
flags.DEFINE_multi_integer('cols', [5, 7, 23],
'Columns to select', flag_values=self.fv)
expected_output = (
'<flag>\n'
' <file>tool</file>\n'
' <name>cols</name>\n'
' <meaning>Columns to select;\n '
'repeat this option to specify a list of values</meaning>\n'
' <default>[5, 7, 23]</default>\n'
' <current>[5, 7, 23]</current>\n'
' <type>multi int</type>\n'
'</flag>\n')
self._check_flag_help_in_xml('cols', 'tool', expected_output)