本文整理汇总了Python中absl.testing.flagsaver.flagsaver方法的典型用法代码示例。如果您正苦于以下问题:Python flagsaver.flagsaver方法的具体用法?Python flagsaver.flagsaver怎么用?Python flagsaver.flagsaver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.testing.flagsaver
的用法示例。
在下文中一共展示了flagsaver.flagsaver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_train_and_eval
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_train_and_eval(self):
data_dir = tf.compat.v1.test.get_temp_dir()
data_file = os.path.join(data_dir, "elwc.tfrecord")
if tf.io.gfile.exists(data_file):
tf.io.gfile.remove(data_file)
with tf.io.TFRecordWriter(data_file) as writer:
for elwc in [ELWC] * 10:
writer.write(elwc.SerializeToString())
model_dir = os.path.join(data_dir, "model")
with flagsaver.flagsaver(
train_input_pattern=data_file,
eval_input_pattern=data_file,
model_dir=model_dir,
num_train_steps=10,
list_size=2):
pipeline_example.train_and_eval()
if tf.io.gfile.exists(model_dir):
tf.io.gfile.rmtree(model_dir)
示例2: test_train_and_eval
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_train_and_eval(self, listwise_inference):
data_dir = tf.compat.v1.test.get_temp_dir()
data_file = os.path.join(data_dir, "elwc.tfrecord")
if tf.io.gfile.exists(data_file):
tf.io.gfile.remove(data_file)
with tf.io.TFRecordWriter(data_file) as writer:
for elwc in [ELWC] * 10:
writer.write(elwc.SerializeToString())
model_dir = os.path.join(data_dir, "model")
with flagsaver.flagsaver(
train_path=data_file,
eval_path=data_file,
data_format="example_list_with_context",
model_dir=model_dir,
num_train_steps=10,
listwise_inference=listwise_inference,
group_size=1,
weights_feature_name="doc_weight"):
tf_ranking_tfrecord.train_and_eval()
if tf.io.gfile.exists(model_dir):
tf.io.gfile.rmtree(model_dir)
示例3: test_decorator_without_call
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_decorator_without_call(self):
@flagsaver.flagsaver
def mutate_flags(value):
"""Test function that mutates a flag."""
# The undecorated method mutates --flagsaver_test_flag0 to the given value
# and then returns the value of that flag. If the @flagsaver.flagsaver
# decorator works as designed, then this mutation will be reverted after
# this method returns.
FLAGS.flagsaver_test_flag0 = value
return FLAGS.flagsaver_test_flag0
# mutate_flags returns the flag value before it gets restored by
# the flagsaver decorator. So we check that flag value was
# actually changed in the method's scope.
self.assertEqual('new value',
mutate_flags('new value'))
# But... notice that the flag is now unchanged0.
self.assertEqual('unchanged0', FLAGS.flagsaver_test_flag0)
示例4: test_decorator_with_overrides
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_decorator_with_overrides(self):
@flagsaver.flagsaver(flagsaver_test_flag0='new value')
def mutate_flags():
"""Test function expecting new value."""
# If the @flagsaver.decorator decorator works as designed,
# then the value of the flag should be changed in the scope of
# the method but the change will be reverted after this method
# returns.
return FLAGS.flagsaver_test_flag0
# mutate_flags returns the flag value before it gets restored by
# the flagsaver decorator. So we check that flag value was
# actually changed in the method's scope.
self.assertEqual('new value', mutate_flags())
# But... notice that the flag is now unchanged0.
self.assertEqual('unchanged0', FLAGS.flagsaver_test_flag0)
示例5: test_validator_list_is_restored
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_validator_list_is_restored(self):
self.assertLen(FLAGS['flagsaver_test_flag0'].validators, 1)
original_validators = list(FLAGS['flagsaver_test_flag0'].validators)
@flagsaver.flagsaver
def modify_validators():
def no_space(value):
return ' ' not in value
flags.register_validator('flagsaver_test_flag0', no_space)
self.assertLen(FLAGS['flagsaver_test_flag0'].validators, 2)
modify_validators()
self.assertEqual(
original_validators, FLAGS['flagsaver_test_flag0'].validators)
示例6: test_main
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_main(self, mock_prompt_enum):
with flagsaver.flagsaver(
project=common.DEFAULT, config_file_path=self._valid_config_path,
prefer_gcs=False, app_version='valid-version'):
with self.assertRaises(SystemExit) as exit_err:
gng_impl.main('unused')
self.assertEqual(exit_err.exception.code, 0)
self.assertEqual(mock_prompt_enum.call_count, 1)
示例7: test_main__errors
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_main__errors(self, method):
with mock.patch.object(
gng_impl._Manager, method, side_effect=KeyboardInterrupt()):
with flagsaver.flagsaver(
project=common.DEFAULT,
config_file_path=self._valid_config_path,
prefer_gcs=False):
with self.assertRaises(SystemExit) as exit_err:
gng_impl.main('unused')
self.assertEqual(exit_err.exception.code, 1)
示例8: testTensorRankDisableAsserts
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def testTensorRankDisableAsserts(self):
with flagsaver.flagsaver(enable_asserts=False):
c = tf.placeholder(tf.int32, shape=None)
d = py_utils.HasAtLeastRank(c, 3)
with self.session() as sess:
d_v = sess.run(d, feed_dict={c: np.array([[1, 2]])})
self.assertAllEqual([[1, 2]], d_v)
示例9: test_get_default_benchmark_logger
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_get_default_benchmark_logger(self):
with flagsaver.flagsaver(benchmark_logger_type="foo"):
self.assertIsInstance(logger.get_benchmark_logger(),
logger.BaseBenchmarkLogger)
示例10: test_config_base_benchmark_logger
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_config_base_benchmark_logger(self):
with flagsaver.flagsaver(benchmark_logger_type="BaseBenchmarkLogger"):
logger.config_benchmark_logger()
self.assertIsInstance(logger.get_benchmark_logger(),
logger.BaseBenchmarkLogger)
示例11: test_config_benchmark_file_logger
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_config_benchmark_file_logger(self):
# Set the benchmark_log_dir first since the benchmark_logger_type will need
# the value to be set when it does the validation.
with flagsaver.flagsaver(benchmark_log_dir="/tmp"):
with flagsaver.flagsaver(benchmark_logger_type="BenchmarkFileLogger"):
logger.config_benchmark_logger()
self.assertIsInstance(logger.get_benchmark_logger(),
logger.BenchmarkFileLogger)
示例12: test_config_benchmark_bigquery_logger
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_config_benchmark_bigquery_logger(self, mock_bigquery_client):
with flagsaver.flagsaver(benchmark_logger_type="BenchmarkBigQueryLogger"):
logger.config_benchmark_logger()
self.assertIsInstance(logger.get_benchmark_logger(),
logger.BenchmarkBigQueryLogger)
示例13: test_get_default_benchmark_logger
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_get_default_benchmark_logger(self):
with flagsaver.flagsaver(benchmark_logger_type='foo'):
self.assertIsInstance(logger.get_benchmark_logger(),
logger.BaseBenchmarkLogger)
示例14: test_config_base_benchmark_logger
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_config_base_benchmark_logger(self):
with flagsaver.flagsaver(benchmark_logger_type='BaseBenchmarkLogger'):
logger.config_benchmark_logger()
self.assertIsInstance(logger.get_benchmark_logger(),
logger.BaseBenchmarkLogger)
示例15: test_config_benchmark_file_logger
# 需要导入模块: from absl.testing import flagsaver [as 别名]
# 或者: from absl.testing.flagsaver import flagsaver [as 别名]
def test_config_benchmark_file_logger(self):
# Set the benchmark_log_dir first since the benchmark_logger_type will need
# the value to be set when it does the validation.
with flagsaver.flagsaver(benchmark_log_dir='/tmp'):
with flagsaver.flagsaver(benchmark_logger_type='BenchmarkFileLogger'):
logger.config_benchmark_logger()
self.assertIsInstance(logger.get_benchmark_logger(),
logger.BenchmarkFileLogger)