本文整理汇总了Python中absl.testing.flagsaver.restore_flag_values方法的典型用法代码示例。如果您正苦于以下问题:Python flagsaver.restore_flag_values方法的具体用法?Python flagsaver.restore_flag_values怎么用?Python flagsaver.restore_flag_values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.testing.flagsaver
的用法示例。
在下文中一共展示了flagsaver.restore_flag_values方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restore_flag_values
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def restore_flag_values(saved_flag_values, flag_values=FLAGS):
"""Restores flag values based on the dictionary of flag values.
Args:
saved_flag_values: {'flag_name': value_dict, ...}
flag_values: FlagValues, the FlagValues instance from which the flag will
be restored. This should almost never need to be overridden.
"""
new_flag_names = list(flag_values)
for name in new_flag_names:
saved = saved_flag_values.get(name)
if saved is None:
# If __dict__ was not saved delete "new" flag.
delattr(flag_values, name)
else:
if flag_values[name].value != saved['_value']:
flag_values[name].value = saved['_value'] # Ensure C++ value is set.
flag_values[name].__dict__ = saved
示例2: tearDown
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def tearDown(self):
super(BeyondcorpTest, self).tearDown()
flagsaver.restore_flag_values(self.__saved_flags)
示例3: __enter__
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def __enter__(self):
self._saved_flag_values = save_flag_values(FLAGS)
try:
for name, value in six.iteritems(self._overrides):
setattr(FLAGS, name, value)
except:
# It may fail because of flag validators.
restore_flag_values(self._saved_flag_values, FLAGS)
raise
示例4: __exit__
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
restore_flag_values(self._saved_flag_values, FLAGS)
示例5: test_save_flag_value
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def test_save_flag_value(self):
# First save the flag values.
saved_flag_values = flagsaver.save_flag_values()
# Now mutate the flag's value field and check that it changed.
FLAGS.flagsaver_test_flag0 = 'new value'
self.assertEqual('new value', FLAGS.flagsaver_test_flag0)
# Now restore the flag to its original value.
flagsaver.restore_flag_values(saved_flag_values)
self.assertEqual('unchanged0', FLAGS.flagsaver_test_flag0)
示例6: test_save_flag_default
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def test_save_flag_default(self):
# First save the flag.
saved_flag_values = flagsaver.save_flag_values()
# Now mutate the flag's default field and check that it changed.
FLAGS.set_default('flagsaver_test_flag0', 'new_default')
self.assertEqual('new_default', FLAGS['flagsaver_test_flag0'].default)
# Now restore the flag's default field.
flagsaver.restore_flag_values(saved_flag_values)
self.assertEqual('unchanged0', FLAGS['flagsaver_test_flag0'].default)
示例7: tearDown
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def tearDown(self):
flagsaver.restore_flag_values(self.saved_flag_values)
示例8: _setup
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def _setup(self):
"""Sets up and resets flags before each test."""
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.DEBUG)
if NCFKerasBenchmarkBase.local_flags is None:
ncf_common.define_ncf_flags()
# Loads flags to get defaults to then override. List cannot be empty.
flags.FLAGS(['foo'])
core.set_defaults(**self.default_flags)
saved_flag_values = flagsaver.save_flag_values()
NCFKerasBenchmarkBase.local_flags = saved_flag_values
else:
flagsaver.restore_flag_values(NCFKerasBenchmarkBase.local_flags)
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:14,代码来源:ncf_keras_benchmark.py
示例9: _setup
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def _setup(self):
"""Sets up and resets flags before each test."""
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.DEBUG)
if PerfZeroBenchmark.local_flags is None:
for flag_method in self.flag_methods:
flag_method()
# Loads flags to get defaults to then override. List cannot be empty.
flags.FLAGS(['foo'])
# Overrides flag values with defaults for the class of tests.
for k, v in self.default_flags.items():
setattr(FLAGS, k, v)
saved_flag_values = flagsaver.save_flag_values()
PerfZeroBenchmark.local_flags = saved_flag_values
else:
flagsaver.restore_flag_values(PerfZeroBenchmark.local_flags)
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:17,代码来源:perfzero_benchmark.py
示例10: _setup
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def _setup(self):
"""Sets up and resets flags before each test."""
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.DEBUG)
if EstimatorBenchmark.local_flags is None:
for flag_method in self.flag_methods:
flag_method()
# Loads flags to get defaults to then override. List cannot be empty.
flags.FLAGS(['foo'])
# Overrides flag values with defaults for the class of tests.
for k, v in self.default_flags.items():
setattr(FLAGS, k, v)
saved_flag_values = flagsaver.save_flag_values()
EstimatorBenchmark.local_flags = saved_flag_values
else:
flagsaver.restore_flag_values(EstimatorBenchmark.local_flags)
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:17,代码来源:estimator_benchmark.py
示例11: _setup
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def _setup(self):
"""Sets up and resets flags before each test."""
self.timer_callback = BenchmarkTimerCallback()
if BertBenchmarkBase.local_flags is None:
# Loads flags to get defaults to then override. List cannot be empty.
flags.FLAGS(['foo'])
saved_flag_values = flagsaver.save_flag_values()
BertBenchmarkBase.local_flags = saved_flag_values
else:
flagsaver.restore_flag_values(BertBenchmarkBase.local_flags)
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:13,代码来源:benchmark_utils.py
示例12: setUp
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def setUp(self):
temp_dir = self.get_temp_dir()
if TransformerTaskTest.local_flags is None:
misc.define_transformer_flags()
# Loads flags, array cannot be blank.
flags.FLAGS(['foo'])
TransformerTaskTest.local_flags = flagsaver.save_flag_values()
else:
flagsaver.restore_flag_values(TransformerTaskTest.local_flags)
FLAGS.model_dir = os.path.join(temp_dir, FIXED_TIMESTAMP)
FLAGS.param_set = 'tiny'
FLAGS.use_synthetic_data = True
FLAGS.steps_between_evals = 1
FLAGS.train_steps = 2
FLAGS.validation_steps = 1
FLAGS.batch_size = 8
FLAGS.num_gpus = 1
FLAGS.distribution_strategy = 'off'
FLAGS.dtype = 'fp32'
self.model_dir = FLAGS.model_dir
self.temp_dir = temp_dir
self.vocab_file = os.path.join(temp_dir, 'vocab')
self.vocab_size = misc.get_model_params(FLAGS.param_set, 0)['vocab_size']
self.bleu_source = os.path.join(temp_dir, 'bleu_source')
self.bleu_ref = os.path.join(temp_dir, 'bleu_ref')
self.orig_policy = (
tf.compat.v2.keras.mixed_precision.experimental.global_policy())
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:29,代码来源:transformer_main_test.py
示例13: _setup
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def _setup(self):
tf.logging.set_verbosity(tf.logging.DEBUG)
if EstimatorCifar10BenchmarkTests.local_flags is None:
cifar_main.define_cifar_flags()
# Loads flags to get defaults to then override.
flags.FLAGS(['foo'])
saved_flag_values = flagsaver.save_flag_values()
EstimatorCifar10BenchmarkTests.local_flags = saved_flag_values
return
flagsaver.restore_flag_values(EstimatorCifar10BenchmarkTests.local_flags)
示例14: _setup
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def _setup(self):
"""Setups up and resets flags before each test."""
tf.logging.set_verbosity(tf.logging.DEBUG)
if KerasImagenetBenchmarkTests.local_flags is None:
keras_common.define_keras_flags()
imagenet_main.define_imagenet_flags()
# Loads flags to get defaults to then override. List cannot be empty.
flags.FLAGS(['foo'])
saved_flag_values = flagsaver.save_flag_values()
KerasImagenetBenchmarkTests.local_flags = saved_flag_values
return
flagsaver.restore_flag_values(KerasImagenetBenchmarkTests.local_flags)
示例15: _setup
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import restore_flag_values [as 别名]
def _setup(self):
"""Setups up and resets flags before each test."""
tf.logging.set_verbosity(tf.logging.DEBUG)
if KerasCifar10BenchmarkTests.local_flags is None:
keras_common.define_keras_flags()
cifar_main.define_cifar_flags()
# Loads flags to get defaults to then override. List cannot be empty.
flags.FLAGS(['foo'])
saved_flag_values = flagsaver.save_flag_values()
KerasCifar10BenchmarkTests.local_flags = saved_flag_values
return
flagsaver.restore_flag_values(KerasCifar10BenchmarkTests.local_flags)