diff options
author | Justine Tunney <jart@google.com> | 2017-12-01 15:48:30 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-12-01 15:52:16 -0800 |
commit | de1ee126c094c840668d5e794e347159be66b23c (patch) | |
tree | db08e88ab5f2272afef936f2c22457d9282c59dc | |
parent | ab0c520c7f58386e0141a3c515acea19033410a6 (diff) |
Rename create_summary_file_writer to create_file_writer
PiperOrigin-RevId: 177651937
15 files changed, 57 insertions, 47 deletions
diff --git a/tensorflow/contrib/eager/python/evaluator.py b/tensorflow/contrib/eager/python/evaluator.py index bd0ab02ecf..3faaeef590 100644 --- a/tensorflow/contrib/eager/python/evaluator.py +++ b/tensorflow/contrib/eager/python/evaluator.py @@ -110,7 +110,7 @@ class Evaluator(object): return self._all_metric_results() else: def f(): - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( summary_logdir).as_default(), summary_ops.always_record_summaries(): return self._all_metric_results() if context.in_eager_mode(): diff --git a/tensorflow/contrib/eager/python/examples/linear_regression/linear_regression.py b/tensorflow/contrib/eager/python/examples/linear_regression/linear_regression.py index d0130ebd11..7bc5007c56 100644 --- a/tensorflow/contrib/eager/python/examples/linear_regression/linear_regression.py +++ b/tensorflow/contrib/eager/python/examples/linear_regression/linear_regression.py @@ -85,7 +85,7 @@ def fit(model, dataset, optimizer, verbose=False, logdir=None): if logdir: # Support for TensorBoard summaries. Once training has started, use: # tensorboard --logdir=<logdir> - summary_writer = tf.contrib.summary.create_summary_file_writer(logdir) + summary_writer = tf.contrib.summary.create_file_writer(logdir) # Training loop. for i, (xs, ys) in enumerate(tfe.Iterator(dataset)): diff --git a/tensorflow/contrib/eager/python/examples/mnist/mnist.py b/tensorflow/contrib/eager/python/examples/mnist/mnist.py index bfb7d5a900..bb121c7704 100644 --- a/tensorflow/contrib/eager/python/examples/mnist/mnist.py +++ b/tensorflow/contrib/eager/python/examples/mnist/mnist.py @@ -190,9 +190,9 @@ def main(_): else: train_dir = None test_dir = None - summary_writer = tf.contrib.summary.create_summary_file_writer( + summary_writer = tf.contrib.summary.create_file_writer( train_dir, flush_millis=10000) - test_summary_writer = tf.contrib.summary.create_summary_file_writer( + test_summary_writer = tf.contrib.summary.create_file_writer( test_dir, flush_millis=10000, name='test') checkpoint_prefix = os.path.join(FLAGS.checkpoint_dir, 'ckpt') diff --git a/tensorflow/contrib/eager/python/examples/resnet50/resnet50_graph_test.py b/tensorflow/contrib/eager/python/examples/resnet50/resnet50_graph_test.py index 14c82c87a7..23317886e7 100644 --- a/tensorflow/contrib/eager/python/examples/resnet50/resnet50_graph_test.py +++ b/tensorflow/contrib/eager/python/examples/resnet50/resnet50_graph_test.py @@ -73,7 +73,7 @@ class ResNet50GraphTest(tf.test.TestCase): tf.train.get_or_create_global_step() logdir = tempfile.mkdtemp() with tf.contrib.summary.always_record_summaries(): - with tf.contrib.summary.create_summary_file_writer( + with tf.contrib.summary.create_file_writer( logdir, max_queue=0, name='t0').as_default(): model = resnet50.ResNet50(data_format()) diff --git a/tensorflow/contrib/eager/python/examples/resnet50/resnet50_test.py b/tensorflow/contrib/eager/python/examples/resnet50/resnet50_test.py index 582f4837c6..d8d8644dde 100644 --- a/tensorflow/contrib/eager/python/examples/resnet50/resnet50_test.py +++ b/tensorflow/contrib/eager/python/examples/resnet50/resnet50_test.py @@ -95,7 +95,7 @@ class ResNet50Test(tf.test.TestCase): model = resnet50.ResNet50(data_format) tf.train.get_or_create_global_step() logdir = tempfile.mkdtemp() - with tf.contrib.summary.create_summary_file_writer( + with tf.contrib.summary.create_file_writer( logdir, max_queue=0, name='t0').as_default(), tf.contrib.summary.always_record_summaries(): with tf.device(device): diff --git a/tensorflow/contrib/eager/python/examples/rnn_colorbot/rnn_colorbot.py b/tensorflow/contrib/eager/python/examples/rnn_colorbot/rnn_colorbot.py index 609cbd2877..40919f2d4c 100644 --- a/tensorflow/contrib/eager/python/examples/rnn_colorbot/rnn_colorbot.py +++ b/tensorflow/contrib/eager/python/examples/rnn_colorbot/rnn_colorbot.py @@ -247,9 +247,9 @@ def main(_): log_dir = os.path.join(FLAGS.dir, "summaries") tf.gfile.MakeDirs(log_dir) - train_summary_writer = tf.contrib.summary.create_summary_file_writer( + train_summary_writer = tf.contrib.summary.create_file_writer( os.path.join(log_dir, "train"), flush_millis=10000) - test_summary_writer = tf.contrib.summary.create_summary_file_writer( + test_summary_writer = tf.contrib.summary.create_file_writer( os.path.join(log_dir, "eval"), flush_millis=10000, name="eval") with tf.device(device): diff --git a/tensorflow/contrib/eager/python/g3doc/guide.md b/tensorflow/contrib/eager/python/g3doc/guide.md index 147b7047f4..0095ffa0db 100644 --- a/tensorflow/contrib/eager/python/g3doc/guide.md +++ b/tensorflow/contrib/eager/python/g3doc/guide.md @@ -757,7 +757,7 @@ For example, to record summaries once every 100 global steps, use: ```python tf.train.get_or_create_global_step() # Ensuring the global step variable exists -writer = tf.contrib.summary.create_summary_file_writer(logdir) +writer = tf.contrib.summary.create_file_writer(logdir) for _ in range(iterations): with writer.as_default(): diff --git a/tensorflow/contrib/eager/python/metrics_test.py b/tensorflow/contrib/eager/python/metrics_test.py index 96eb1b4f2a..1055f4563c 100644 --- a/tensorflow/contrib/eager/python/metrics_test.py +++ b/tensorflow/contrib/eager/python/metrics_test.py @@ -67,7 +67,7 @@ class MetricsTest(test.TestCase): m([1, 10, 100]) training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logdir, max_queue=0, name="t0").as_default(), summary_ops.always_record_summaries(): m.result() # As a side-effect will write summaries. diff --git a/tensorflow/contrib/summary/summary.py b/tensorflow/contrib/summary/summary.py index 9e6af5232f..7d3b8b7437 100644 --- a/tensorflow/contrib/summary/summary.py +++ b/tensorflow/contrib/summary/summary.py @@ -28,7 +28,8 @@ from __future__ import print_function from tensorflow.contrib.summary.summary_ops import all_summary_ops from tensorflow.contrib.summary.summary_ops import always_record_summaries from tensorflow.contrib.summary.summary_ops import audio -from tensorflow.contrib.summary.summary_ops import create_summary_db_writer +from tensorflow.contrib.summary.summary_ops import create_db_writer +from tensorflow.contrib.summary.summary_ops import create_file_writer from tensorflow.contrib.summary.summary_ops import create_summary_file_writer from tensorflow.contrib.summary.summary_ops import eval_dir from tensorflow.contrib.summary.summary_ops import flush diff --git a/tensorflow/contrib/summary/summary_ops.py b/tensorflow/contrib/summary/summary_ops.py index de6f2cd79f..4556162bfe 100644 --- a/tensorflow/contrib/summary/summary_ops.py +++ b/tensorflow/contrib/summary/summary_ops.py @@ -38,9 +38,11 @@ from tensorflow.python.ops import control_flow_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import resource_variable_ops from tensorflow.python.ops import summary_op_util +from tensorflow.python.platform import tf_logging as logging from tensorflow.python.training import training_util from tensorflow.python.util import tf_contextlib + # Name for a collection which is expected to have at most a single boolean # Tensor. If this tensor is True the summary ops will record summaries. _SHOULD_RECORD_SUMMARIES_NAME = "ShouldRecordSummaries" @@ -102,8 +104,8 @@ class SummaryWriter(object): """Encapsulates a stateful summary writer resource. See also: - - @{tf.contrib.summary.create_summary_file_writer} - - @{tf.contrib.summary.create_summary_db_writer} + - @{tf.contrib.summary.create_file_writer} + - @{tf.contrib.summary.create_db_writer} """ def __init__(self, resource): @@ -169,11 +171,11 @@ def initialize( session.run(_graph(x, 0), feed_dict={x: data}) -def create_summary_file_writer(logdir, - max_queue=None, - flush_millis=None, - filename_suffix=None, - name=None): +def create_file_writer(logdir, + max_queue=None, + flush_millis=None, + filename_suffix=None, + name=None): """Creates a summary file writer in the current context. Args: @@ -210,11 +212,11 @@ def create_summary_file_writer(logdir, filename_suffix=filename_suffix) -def create_summary_db_writer(db_uri, - experiment_name=None, - run_name=None, - user_name=None, - name=None): +def create_db_writer(db_uri, + experiment_name=None, + run_name=None, + user_name=None, + name=None): """Creates a summary database writer in the current context. This can be used to write tensors from the execution graph directly @@ -498,7 +500,7 @@ _graph = graph # for functions with a graph parameter def import_event(tensor, name=None): """Writes a @{tf.Event} binary proto. - When using create_summary_db_writer(), this can be used alongside + When using create_db_writer(), this can be used alongside @{tf.TFRecordReader} to load event logs into the database. Please note that this is lower level than the other summary functions and will ignore any conditions set by methods like @@ -542,6 +544,13 @@ def eval_dir(model_dir, name=None): return os.path.join(model_dir, "eval" if not name else "eval_" + name) +def create_summary_file_writer(*args, **kwargs): + """Please use @{tf.contrib.summary.create_file_writer}.""" + logging.warning("Deprecation Warning: create_summary_file_writer was renamed " + "to create_file_writer") + return create_file_writer(*args, **kwargs) + + def _serialize_graph(arbitrary_graph): if isinstance(arbitrary_graph, ops.Graph): return arbitrary_graph.as_graph_def(add_shapes=True).SerializeToString() diff --git a/tensorflow/contrib/summary/summary_ops_graph_test.py b/tensorflow/contrib/summary/summary_ops_graph_test.py index 703adb7b46..f8da790188 100644 --- a/tensorflow/contrib/summary/summary_ops_graph_test.py +++ b/tensorflow/contrib/summary/summary_ops_graph_test.py @@ -48,7 +48,7 @@ class DbTest(summary_test_util.SummaryDbTest): name = 'hi' graph = graph_pb2.GraphDef(node=(node_def_pb2.NodeDef(name=name),)) with self.test_session(): - with self.create_summary_db_writer().as_default(): + with self.create_db_writer().as_default(): summary_ops.initialize(graph=graph) six.assertCountEqual(self, [name], get_all(self.db, 'SELECT node_name FROM Nodes')) @@ -57,7 +57,7 @@ class DbTest(summary_test_util.SummaryDbTest): with ops.Graph().as_default(), self.test_session(): training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logdir, max_queue=0, name='t2').as_default(), summary_ops.always_record_summaries(): summary_ops.initialize() @@ -78,7 +78,7 @@ class DbTest(summary_test_util.SummaryDbTest): with ops.Graph().as_default(), self.test_session(): training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logdir, max_queue=0, name='t2').as_default(), summary_ops.always_record_summaries(): summary_ops.initialize() diff --git a/tensorflow/contrib/summary/summary_ops_test.py b/tensorflow/contrib/summary/summary_ops_test.py index 54433deb28..0b8e0b967c 100644 --- a/tensorflow/contrib/summary/summary_ops_test.py +++ b/tensorflow/contrib/summary/summary_ops_test.py @@ -44,7 +44,7 @@ class TargetTest(test_util.TensorFlowTestCase): logdir = '/tmp/apath/that/doesnt/exist' self.assertFalse(gfile.Exists(logdir)) with self.assertRaises(errors.NotFoundError): - summary_ops.create_summary_file_writer(logdir, max_queue=0, name='t0') + summary_ops.create_file_writer(logdir, max_queue=0, name='t0') def testShouldRecordSummary(self): self.assertFalse(summary_ops.should_record_summaries()) @@ -54,7 +54,7 @@ class TargetTest(test_util.TensorFlowTestCase): def testSummaryOps(self): training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logdir, max_queue=0, name='t0').as_default(), summary_ops.always_record_summaries(): summary_ops.generic('tensor', 1, '') @@ -69,7 +69,7 @@ class TargetTest(test_util.TensorFlowTestCase): def testDefunSummarys(self): training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logdir, max_queue=0, name='t1').as_default(), summary_ops.always_record_summaries(): @@ -85,7 +85,7 @@ class TargetTest(test_util.TensorFlowTestCase): def testSummaryName(self): training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logdir, max_queue=0, name='t2').as_default(), summary_ops.always_record_summaries(): @@ -98,7 +98,7 @@ class TargetTest(test_util.TensorFlowTestCase): def testSummaryGlobalStep(self): step = training_util.get_or_create_global_step() logdir = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logdir, max_queue=0, name='t2').as_default(), summary_ops.always_record_summaries(): @@ -110,7 +110,7 @@ class TargetTest(test_util.TensorFlowTestCase): def testMaxQueue(self): logs = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logs, max_queue=2, flush_millis=999999, name='lol').as_default(), summary_ops.always_record_summaries(): get_total = lambda: len(summary_test_util.events_from_logdir(logs)) @@ -123,7 +123,7 @@ class TargetTest(test_util.TensorFlowTestCase): def testFlush(self): logs = tempfile.mkdtemp() - with summary_ops.create_summary_file_writer( + with summary_ops.create_file_writer( logs, max_queue=999999, flush_millis=999999, name='lol').as_default(), summary_ops.always_record_summaries(): get_total = lambda: len(summary_test_util.events_from_logdir(logs)) @@ -150,7 +150,7 @@ class DbTest(summary_test_util.SummaryDbTest): return sum_ with summary_ops.always_record_summaries(): - with self.create_summary_db_writer().as_default(): + with self.create_db_writer().as_default(): self.assertEqual(5, adder(int64(2), int64(3)).numpy()) six.assertCountEqual(self, [1, 1, 1], @@ -162,7 +162,7 @@ class DbTest(summary_test_util.SummaryDbTest): sum_id = get_one(self.db, 'SELECT tag_id FROM Tags WHERE tag_name = "sum"') with summary_ops.always_record_summaries(): - with self.create_summary_db_writer().as_default(): + with self.create_db_writer().as_default(): self.assertEqual(9, adder(int64(4), int64(5)).numpy()) six.assertCountEqual(self, [1, 1, 1, 2, 2, 2], @@ -185,26 +185,26 @@ class DbTest(summary_test_util.SummaryDbTest): def testBadExperimentName(self): with self.assertRaises(ValueError): - self.create_summary_db_writer(experiment_name='\0') + self.create_db_writer(experiment_name='\0') def testBadRunName(self): with self.assertRaises(ValueError): - self.create_summary_db_writer(run_name='\0') + self.create_db_writer(run_name='\0') def testBadUserName(self): with self.assertRaises(ValueError): - self.create_summary_db_writer(user_name='-hi') + self.create_db_writer(user_name='-hi') with self.assertRaises(ValueError): - self.create_summary_db_writer(user_name='hi-') + self.create_db_writer(user_name='hi-') with self.assertRaises(ValueError): - self.create_summary_db_writer(user_name='@') + self.create_db_writer(user_name='@') def testGraphSummary(self): training_util.get_or_create_global_step() name = 'hi' graph = graph_pb2.GraphDef(node=(node_def_pb2.NodeDef(name=name),)) with summary_ops.always_record_summaries(): - with self.create_summary_db_writer().as_default(): + with self.create_db_writer().as_default(): summary_ops.graph(graph) six.assertCountEqual(self, [name], get_all(self.db, 'SELECT node_name FROM Nodes')) diff --git a/tensorflow/contrib/summary/summary_test_internal.py b/tensorflow/contrib/summary/summary_test_internal.py index 54233f2f50..80f60ae401 100644 --- a/tensorflow/contrib/summary/summary_test_internal.py +++ b/tensorflow/contrib/summary/summary_test_internal.py @@ -35,8 +35,8 @@ class SummaryDbTest(test_util.TensorFlowTestCase): if os.path.exists(self.db_path): os.unlink(self.db_path) self.db = sqlite3.connect(self.db_path) - self.create_summary_db_writer = functools.partial( - summary_ops.create_summary_db_writer, + self.create_db_writer = functools.partial( + summary_ops.create_db_writer, db_uri=self.db_path, experiment_name='experiment', run_name='run', diff --git a/tensorflow/contrib/summary/summary_test_util.py b/tensorflow/contrib/summary/summary_test_util.py index 915820e05b..bda57e6a0c 100644 --- a/tensorflow/contrib/summary/summary_test_util.py +++ b/tensorflow/contrib/summary/summary_test_util.py @@ -39,8 +39,8 @@ class SummaryDbTest(test_util.TensorFlowTestCase): if os.path.exists(self.db_path): os.unlink(self.db_path) self.db = sqlite3.connect(self.db_path) - self.create_summary_db_writer = functools.partial( - summary_ops.create_summary_db_writer, + self.create_db_writer = functools.partial( + summary_ops.create_db_writer, db_uri=self.db_path, experiment_name='experiment', run_name='run', diff --git a/third_party/examples/eager/spinn/spinn.py b/third_party/examples/eager/spinn/spinn.py index 963ac0e65b..a2fa18eeb1 100644 --- a/third_party/examples/eager/spinn/spinn.py +++ b/third_party/examples/eager/spinn/spinn.py @@ -567,7 +567,7 @@ def train_spinn(embed, train_data, dev_data, test_data, config): "{:>6.0f} {:>5.0f} {:>9.0f} {:>5.0f}/{:<5.0f} {:>7.0f}% {:>8.6f} " "{:8.6f} {:12.4f} {:12.4f}") - summary_writer = tf.contrib.summary.create_summary_file_writer( + summary_writer = tf.contrib.summary.create_file_writer( config.logdir, flush_millis=10000) train_len = train_data.num_batches(config.batch_size) with tf.device(device), \ |