aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/summary/summary_ops_graph_test.py
diff options
context:
space:
mode:
authorGravatar Igor Ganichev <iga@google.com>2017-12-12 14:33:55 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-12-12 14:37:34 -0800
commitd0a4a79c02b8c2a64763e1ef02c878f34e9defff (patch)
tree8ee3f5988a2eaad8a7e5968e880c3dc0565d0c5e /tensorflow/contrib/summary/summary_ops_graph_test.py
parent389ffa842b0c0e7344ac721bbee8639de96cc81e (diff)
Add test case for record_summaries_every_n_global_steps
This test case illustrates how to use record_summaries_every_n_global_steps and tf.all_summaries() in graph mode. There are no tests using record_summaries_every_n_global_steps. All existing graph based tests don't use tf.all_summaries() creating the impression that summary ops will somehow always run, which is not the case. PiperOrigin-RevId: 178816316
Diffstat (limited to 'tensorflow/contrib/summary/summary_ops_graph_test.py')
-rw-r--r--tensorflow/contrib/summary/summary_ops_graph_test.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tensorflow/contrib/summary/summary_ops_graph_test.py b/tensorflow/contrib/summary/summary_ops_graph_test.py
index f8da790188..42ebb7ab9d 100644
--- a/tensorflow/contrib/summary/summary_ops_graph_test.py
+++ b/tensorflow/contrib/summary/summary_ops_graph_test.py
@@ -29,6 +29,7 @@ from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import control_flow_ops
+from tensorflow.python.ops import state_ops
from tensorflow.python.platform import test
from tensorflow.python.training import training_util
@@ -53,6 +54,37 @@ class DbTest(summary_test_util.SummaryDbTest):
six.assertCountEqual(self, [name],
get_all(self.db, 'SELECT node_name FROM Nodes'))
+ def testScalarSummary(self):
+ """Test record_summaries_every_n_global_steps and all_summaries()."""
+ with ops.Graph().as_default(), self.test_session() as sess:
+ global_step = training_util.get_or_create_global_step()
+ global_step.initializer.run()
+ with ops.device('/cpu:0'):
+ step_increment = state_ops.assign_add(global_step, 1)
+ sess.run(step_increment) # Increment global step from 0 to 1
+
+ logdir = tempfile.mkdtemp()
+ with summary_ops.create_file_writer(logdir, max_queue=0,
+ name='t2').as_default():
+ with summary_ops.record_summaries_every_n_global_steps(2):
+ summary_ops.initialize()
+ summary_op = summary_ops.scalar('my_scalar', 2.0)
+
+ # Neither of these should produce a summary because
+ # global_step is 1 and "1 % 2 != 0"
+ sess.run(summary_ops.all_summary_ops())
+ sess.run(summary_op)
+ events = summary_test_util.events_from_logdir(logdir)
+ self.assertEqual(len(events), 1)
+
+ # Increment global step from 1 to 2 and check that the summary
+ # is now written
+ sess.run(step_increment)
+ sess.run(summary_ops.all_summary_ops())
+ events = summary_test_util.events_from_logdir(logdir)
+ self.assertEqual(len(events), 2)
+ self.assertEqual(events[1].summary.value[0].tag, 'cond/my_scalar')
+
def testSummaryGraphModeCond(self):
with ops.Graph().as_default(), self.test_session():
training_util.get_or_create_global_step()