diff --git a/tensorboard/backend/event_processing/plugin_event_accumulator_test.py b/tensorboard/backend/event_processing/plugin_event_accumulator_test.py index 4961fccf1a..99e2fe8089 100644 --- a/tensorboard/backend/event_processing/plugin_event_accumulator_test.py +++ b/tensorboard/backend/event_processing/plugin_event_accumulator_test.py @@ -121,7 +121,6 @@ def assertTagsEqual(self, actual, expected): self.assertEqual(actual[key], expected_value) -@test_util.run_v1_only('Uses v1 SummaryWriter and v1 audio summary') class MockingEventAccumulatorTest(EventAccumulatorTest): def setUp(self): @@ -358,15 +357,16 @@ def testNewStyleScalarSummary(self): event_sink = _EventGenerator(self, zero_out_timestamps=True) writer = test_util.FileWriter(self.get_temp_dir()) writer.event_writer = event_sink - with self.test_session() as sess: - step = tf.compat.v1.placeholder(tf.float32, shape=[]) - scalar_summary.op('accuracy', 1.0 - 1.0 / (step + tf.constant(1.0))) - scalar_summary.op('xent', 1.0 / (step + tf.constant(1.0))) - merged = tf.compat.v1.summary.merge_all() - writer.add_graph(sess.graph) - for i in xrange(10): - summ = sess.run(merged, feed_dict={step: float(i)}) - writer.add_summary(summ, global_step=i) + with tf.compat.v1.Graph().as_default(): + with self.test_session() as sess: + step = tf.compat.v1.placeholder(tf.float32, shape=[]) + scalar_summary.op('accuracy', 1.0 - 1.0 / (step + tf.constant(1.0))) + scalar_summary.op('xent', 1.0 / (step + tf.constant(1.0))) + merged = tf.compat.v1.summary.merge_all() + writer.add_graph(sess.graph) + for i in xrange(10): + summ = sess.run(merged, feed_dict={step: float(i)}) + writer.add_summary(summ, global_step=i) accumulator = ea.EventAccumulator(event_sink) accumulator.Reload() @@ -387,19 +387,20 @@ def testNewStyleAudioSummary(self): event_sink = _EventGenerator(self, zero_out_timestamps=True) writer = test_util.FileWriter(self.get_temp_dir()) writer.event_writer = event_sink - with self.test_session() as sess: - ipt = tf.random.normal(shape=[5, 441, 2]) - with tf.name_scope('1'): - audio_summary.op('one', ipt, sample_rate=44100, max_outputs=1) - with tf.name_scope('2'): - audio_summary.op('two', ipt, sample_rate=44100, max_outputs=2) - with tf.name_scope('3'): - audio_summary.op('three', ipt, sample_rate=44100, max_outputs=3) - merged = tf.compat.v1.summary.merge_all() - writer.add_graph(sess.graph) - for i in xrange(10): - summ = sess.run(merged) - writer.add_summary(summ, global_step=i) + with tf.compat.v1.Graph().as_default(): + with self.test_session() as sess: + ipt = tf.random.normal(shape=[5, 441, 2]) + with tf.name_scope('1'): + audio_summary.op('one', ipt, sample_rate=44100, max_outputs=1) + with tf.name_scope('2'): + audio_summary.op('two', ipt, sample_rate=44100, max_outputs=2) + with tf.name_scope('3'): + audio_summary.op('three', ipt, sample_rate=44100, max_outputs=3) + merged = tf.compat.v1.summary.merge_all() + writer.add_graph(sess.graph) + for i in xrange(10): + summ = sess.run(merged) + writer.add_summary(summ, global_step=i) accumulator = ea.EventAccumulator(event_sink) accumulator.Reload() @@ -421,23 +422,24 @@ def testNewStyleImageSummary(self): event_sink = _EventGenerator(self, zero_out_timestamps=True) writer = test_util.FileWriter(self.get_temp_dir()) writer.event_writer = event_sink - with self.test_session() as sess: - ipt = tf.ones([10, 4, 4, 3], tf.uint8) - # This is an interesting example, because the old tf.image_summary op - # would throw an error here, because it would be tag reuse. - # Using the tf node name instead allows argument re-use to the image - # summary. - with tf.name_scope('1'): - image_summary.op('images', ipt, max_outputs=1) - with tf.name_scope('2'): - image_summary.op('images', ipt, max_outputs=2) - with tf.name_scope('3'): - image_summary.op('images', ipt, max_outputs=3) - merged = tf.compat.v1.summary.merge_all() - writer.add_graph(sess.graph) - for i in xrange(10): - summ = sess.run(merged) - writer.add_summary(summ, global_step=i) + with tf.compat.v1.Graph().as_default(): + with self.test_session() as sess: + ipt = tf.ones([10, 4, 4, 3], tf.uint8) + # This is an interesting example, because the old tf.image_summary op + # would throw an error here, because it would be tag reuse. + # Using the tf node name instead allows argument re-use to the image + # summary. + with tf.name_scope('1'): + image_summary.op('images', ipt, max_outputs=1) + with tf.name_scope('2'): + image_summary.op('images', ipt, max_outputs=2) + with tf.name_scope('3'): + image_summary.op('images', ipt, max_outputs=3) + merged = tf.compat.v1.summary.merge_all() + writer.add_graph(sess.graph) + for i in xrange(10): + summ = sess.run(merged) + writer.add_summary(summ, global_step=i) accumulator = ea.EventAccumulator(event_sink) accumulator.Reload() @@ -459,13 +461,15 @@ def testTFSummaryTensor(self): event_sink = _EventGenerator(self, zero_out_timestamps=True) writer = test_util.FileWriter(self.get_temp_dir()) writer.event_writer = event_sink - with self.test_session() as sess: - tf.compat.v1.summary.tensor_summary('scalar', tf.constant(1.0)) - tf.compat.v1.summary.tensor_summary('vector', tf.constant([1.0, 2.0, 3.0])) - tf.compat.v1.summary.tensor_summary('string', tf.constant(six.b('foobar'))) - merged = tf.compat.v1.summary.merge_all() - summ = sess.run(merged) - writer.add_summary(summ, 0) + with tf.compat.v1.Graph().as_default(): + with self.test_session() as sess: + tensor_summary = tf.compat.v1.summary.tensor_summary + tensor_summary('scalar', tf.constant(1.0)) + tensor_summary('vector', tf.constant([1.0, 2.0, 3.0])) + tensor_summary('string', tf.constant(six.b('foobar'))) + merged = tf.compat.v1.summary.merge_all() + summ = sess.run(merged) + writer.add_summary(summ, 0) accumulator = ea.EventAccumulator(event_sink) accumulator.Reload() @@ -493,15 +497,16 @@ def _testTFSummaryTensor_SizeGuidance(self, event_sink = _EventGenerator(self, zero_out_timestamps=True) writer = test_util.FileWriter(self.get_temp_dir()) writer.event_writer = event_sink - with self.test_session() as sess: - summary_metadata = summary_pb2.SummaryMetadata( - plugin_data=summary_pb2.SummaryMetadata.PluginData( - plugin_name=plugin_name, content=b'{}')) - tf.compat.v1.summary.tensor_summary('scalar', tf.constant(1.0), - summary_metadata=summary_metadata) - merged = tf.compat.v1.summary.merge_all() - for step in xrange(steps): - writer.add_summary(sess.run(merged), global_step=step) + with tf.compat.v1.Graph().as_default(): + with self.test_session() as sess: + summary_metadata = summary_pb2.SummaryMetadata( + plugin_data=summary_pb2.SummaryMetadata.PluginData( + plugin_name=plugin_name, content=b'{}')) + tf.compat.v1.summary.tensor_summary('scalar', tf.constant(1.0), + summary_metadata=summary_metadata) + merged = tf.compat.v1.summary.merge_all() + for step in xrange(steps): + writer.add_summary(sess.run(merged), global_step=step) accumulator = ea.EventAccumulator( @@ -548,7 +553,6 @@ def testTFSummaryTensor_SizeGuidance_IgnoreIrrelevantGuidances(self): expected_count=size_small) -@test_util.run_v1_only('Uses contrib and v1 SummaryWriter') class RealisticEventAccumulatorTest(EventAccumulatorTest): def testTensorsRealistically(self): @@ -568,11 +572,11 @@ def FakeScalarSummary(tag, value): with tf.Graph().as_default() as graph: _ = tf.constant([2.0, 1.0]) - # Add a graph to the summary writer. - writer.add_graph(graph) - meta_graph_def = tf.compat.v1.train.export_meta_graph(graph_def=graph.as_graph_def( - add_shapes=True)) - writer.add_meta_graph(meta_graph_def) + # Add a graph to the summary writer. + writer.add_graph(graph) + graph_def = graph.as_graph_def(add_shapes=True) + meta_graph_def = tf.compat.v1.train.export_meta_graph(graph_def=graph_def) + writer.add_meta_graph(meta_graph_def) run_metadata = config_pb2.RunMetadata() device_stats = run_metadata.step_stats.dev_stats.add() @@ -646,12 +650,11 @@ def testGraphFromMetaGraphBecomesAvailable(self): with tf.Graph().as_default() as graph: _ = tf.constant([2.0, 1.0]) - # Add a graph to the summary writer. - meta_graph_def = tf.compat.v1.train.export_meta_graph(graph_def=graph.as_graph_def( - add_shapes=True)) - writer.add_meta_graph(meta_graph_def) - - writer.flush() + # Add a graph to the summary writer. + graph_def = graph.as_graph_def(add_shapes=True) + meta_graph_def = tf.compat.v1.train.export_meta_graph(graph_def=graph_def) + writer.add_meta_graph(meta_graph_def) + writer.flush() # Verify that we can load those events properly acc = ea.EventAccumulator(directory)