def testGraphAndGraphDef(self): with self.assertRaises(ValueError): test_dir = self._CleanTestDir("basics_graph_and_graph_def") with ops.Graph().as_default() as g: constant_op.constant([12], name="douze") gd = g.as_graph_def() sw = writer.FileWriter(test_dir, graph=g, graph_def=gd) sw.close()
def testGraphDefAsPositional(self): test_dir = self._CleanTestDir("basics_positional_graph_def") with ops.Graph().as_default() as g: constant_op.constant([12], name="douze") gd = g.as_graph_def() sw = writer.FileWriter(test_dir, gd) sw.close() self._assertEventsWithGraph(test_dir, g, False)
def testNonBlockingClose(self): test_dir = self._CleanTestDir("non_blocking_close") sw = writer.FileWriter(test_dir) # Sleep 1.2 seconds to make sure event queue is empty. time.sleep(1.2) time_before_close = time.time() sw.close() self._assertRecent(time_before_close)
def testPluginMetadataStrippedFromSubsequentEvents(self): test_dir = self._CleanTestDir("basics") sw = writer.FileWriter(test_dir) sw.add_session_log(event_pb2.SessionLog(status=SessionLog.START), 1) # We add 2 summaries with the same tags. They both have metadata. The writer # should strip the metadata from the second one. value = summary_pb2.Summary.Value(tag="foo", simple_value=10.0) value.metadata.plugin_data.plugin_name = "bar" value.metadata.plugin_data.content = "... content ..." sw.add_summary(summary_pb2.Summary(value=[value]), 10) value = summary_pb2.Summary.Value(tag="foo", simple_value=10.0) value.metadata.plugin_data.plugin_name = "bar" value.metadata.plugin_data.content = "... content ..." sw.add_summary(summary_pb2.Summary(value=[value]), 10) sw.close() rr = self._EventsReader(test_dir) # The first event should list the file_version. ev = next(rr) self._assertRecent(ev.wall_time) self.assertEquals("brain.Event:2", ev.file_version) # The next event should be the START message. ev = next(rr) self._assertRecent(ev.wall_time) self.assertEquals(1, ev.step) self.assertEquals(SessionLog.START, ev.session_log.status) # This is the first event with tag foo. It should contain SummaryMetadata. ev = next(rr) self.assertProtoEquals(""" value { tag: "foo" simple_value: 10.0 metadata { plugin_data { plugin_name: "bar" content: "... content ..." } } } """, ev.summary) # This is the second event with tag foo. It should lack SummaryMetadata # because the file writer should have stripped it. ev = next(rr) self.assertProtoEquals(""" value { tag: "foo" simple_value: 10.0 } """, ev.summary) # We should be done. self.assertRaises(StopIteration, lambda: next(rr))
def GenerateTestData(path): """Generates the test data directory.""" run1_path = os.path.join(path, "run1") os.makedirs(run1_path) writer1 = writer_lib.FileWriter(run1_path) WriteScalarSeries(writer1, "foo/square", lambda x: x * x) WriteScalarSeries(writer1, "bar/square", lambda x: x * x) WriteScalarSeries(writer1, "foo/sin", math.sin) WriteScalarSeries(writer1, "foo/cos", math.cos) WriteHistogramSeries(writer1, "histo1", [[0, 1], [0.3, 1], [0.5, 1], [0.7, 1], [1, 1]]) WriteImageSeries(writer1, "im1") WriteImageSeries(writer1, "im2") WriteAudioSeries(writer1, "au1") run2_path = os.path.join(path, "run2") os.makedirs(run2_path) writer2 = writer_lib.FileWriter(run2_path) WriteScalarSeries(writer2, "foo/square", lambda x: x * x * 2) WriteScalarSeries(writer2, "bar/square", lambda x: x * x * 3) WriteScalarSeries(writer2, "foo/cos", lambda x: math.cos(x) * 2) WriteHistogramSeries(writer2, "histo1", [[0, 2], [0.3, 2], [0.5, 2], [0.7, 2], [1, 2]]) WriteHistogramSeries(writer2, "histo2", [[0, 1], [0.3, 1], [0.5, 1], [0.7, 1], [1, 1]]) WriteImageSeries(writer2, "im1") WriteAudioSeries(writer2, "au2") graph_def = graph_pb2.GraphDef() node1 = graph_def.node.add() node1.name = "a" node1.op = "matmul" node2 = graph_def.node.add() node2.name = "b" node2.op = "matmul" node2.input.extend(["a:0"]) writer1.add_graph(graph_def) node3 = graph_def.node.add() node3.name = "c" node3.op = "matmul" node3.input.extend(["a:0", "b:0"]) writer2.add_graph(graph_def) writer1.close() writer2.close()
def _GenerateEventsData(self): fw = writer.FileWriter(self.log_dir) event = event_pb2.Event( wall_time=1, step=1, summary=summary_pb2.Summary( value=[summary_pb2.Summary.Value(tag='s1', simple_value=0)])) fw.add_event(event) fw.close()
def testNoLogdirButExplicitSummaryWriter(self): logdir = self._test_dir("explicit_summary_writer") with ops.Graph().as_default(): summary.scalar("c1", constant_op.constant(1)) summary.scalar("c2", constant_op.constant(2)) summary.scalar("c3", constant_op.constant(3)) summ = summary.merge_all() sw = writer.FileWriter(logdir) sv = supervisor.Supervisor(logdir="", summary_op=None, summary_writer=sw) meta_graph_def = meta_graph.create_meta_graph_def() sess = sv.prepare_or_wait_for_session("") sv.summary_computed(sess, sess.run(summ)) sess.close() # Wait to make sure everything is written to file before stopping. time.sleep(1) sv.stop() # Check the summary was written to 'logdir' rr = _summary_iterator(logdir) # The first event should list the file_version. ev = next(rr) self.assertEquals("brain.Event:2", ev.file_version) # The next one has the graph. ev = next(rr) ev_graph = graph_pb2.GraphDef() ev_graph.ParseFromString(ev.graph_def) self.assertProtoEquals(sess.graph.as_graph_def(add_shapes=True), ev_graph) # Stored MetaGraphDef ev = next(rr) ev_meta_graph = meta_graph_pb2.MetaGraphDef() ev_meta_graph.ParseFromString(ev.meta_graph_def) self.assertProtoEquals(meta_graph_def, ev_meta_graph) self.assertProtoEquals(sess.graph.as_graph_def(add_shapes=True), ev_meta_graph.graph_def) # The next one should have the values from the summary. ev = next(rr) self.assertProtoEquals( """ value { tag: 'c1' simple_value: 1.0 } value { tag: 'c2' simple_value: 2.0 } value { tag: 'c3' simple_value: 3.0 } """, ev.summary) # The next one should be a stop message if we closed cleanly. ev = next(rr) self.assertEquals(event_pb2.SessionLog.STOP, ev.session_log.status) # We should be done. self.assertRaises(StopIteration, lambda: next(rr))
def begin(self): self._file_writer = writer.FileWriter(self._output_dir, filename_suffix="", session=ops.get_default_session) self._next_step = None self._global_step_tensor = training_util._get_or_create_global_step_read( ) # pylint: disable=protected-access if self._global_step_tensor is None: raise RuntimeError( "Global step should be created to use ProfilerHook.")
def testEventMultiplexerIntegration(self): tempdir = self.get_temp_dir() with ops.Graph().as_default() as g: plugin_instance = plugin_asset.get_plugin_asset(PluginAlpha) plugin_instance.contents = "graph one" plugin_asset.get_plugin_asset(PluginBeta) fw = writer.FileWriter(os.path.join(tempdir, "one")) fw.add_graph(g) fw.close() with ops.Graph().as_default() as g: plugin_instance = plugin_asset.get_plugin_asset(PluginAlpha) plugin_instance.contents = "graph two" fw = writer.FileWriter(os.path.join(tempdir, "two")) fw.add_graph(g) fw.close() multiplexer = event_multiplexer.EventMultiplexer() multiplexer.AddRunsFromDirectory(tempdir) self.assertEqual(multiplexer.PluginAssets("Alpha"), { "one": ["contents.txt"], "two": ["contents.txt"] }) self.assertEqual( multiplexer.RetrievePluginAsset("one", "Alpha", "contents.txt"), "graph one") self.assertEqual( multiplexer.RetrievePluginAsset("one", "Beta", "contents.txt"), "hello world") self.assertEqual( multiplexer.RetrievePluginAsset("two", "Alpha", "contents.txt"), "graph two") self.assertEqual(multiplexer.PluginAssets("Beta"), { "one": ["contents.txt"], "two": [] }) self.assertEqual(multiplexer.PluginAssets("Gamma"), { "one": [], "two": [] })
def testSimplePluginCase(self): tempdir = self.get_temp_dir() with ops.Graph().as_default() as g: plugin_asset.get_plugin_asset(PluginAlpha) fw = writer.FileWriter(tempdir) fw.add_graph(g) self.assertEqual(["Alpha"], plugin_asset_util.ListPlugins(tempdir)) assets = plugin_asset_util.ListAssets(tempdir, "Alpha") self.assertEqual(["contents.txt"], assets) contents = plugin_asset_util.RetrieveAsset(tempdir, "Alpha", "contents.txt") self.assertEqual("hello world", contents)
def testEndpointsNoAssets(self): g = ops.Graph() with g.as_default(): plugin_asset.get_plugin_asset( projector_plugin.ProjectorPluginAsset) fw = writer.FileWriter(self.log_dir, graph=g) fw.close() self._SetupWSGIApp() run_json = self._GetJson('/data/plugin/projector/runs') self.assertEqual(run_json, [])
def begin(self): self._summary_writer = writer.FileWriter( self._checkpoint_dir, session=ops.get_default_session, filename_suffix="") self._global_step_tensor = training_util._get_or_create_global_step_read( ) # pylint: disable=protected-access if self._global_step_tensor is None: raise RuntimeError( "Global step should be created to use CheckpointSaverHook.") for l in self._listeners: l.begin()
def begin(self): if self._summary_writer is None and self._output_dir: self._summary_writer = writer.FileWriter( self._output_dir, session=ops.get_default_session, filename_suffix="") self._global_step_tensor = training_util._get_or_create_global_step_read( ) # pylint: disable=protected-access if self._global_step_tensor is None: raise RuntimeError( "Global step should be created to use StepCounterHook.") self._summary_tag = training_util.get_global_step().op.name + "/sec"
def testNoReferenceToPluginNoSerializationOnDisk(self): logdir = self.get_temp_dir() plugin_dir = os.path.join( logdir, writer._PLUGINS_DIR, projector_plugin.ProjectorPluginAsset.plugin_name) with ops.Graph().as_default() as g: fw = writer.FileWriter(logdir) fw.add_graph(g) self.assertFalse(gfile.Exists(plugin_dir), 'The projector plugin directory should not exist.')
def testEndpointsTensorAndMetadataAssets(self): g = ops.Graph() with g.as_default(): manager = plugin_asset.get_plugin_asset( projector_plugin.ProjectorPluginAsset) metadata = projector_plugin.EmbeddingMetadata(3) metadata.add_column('labels', ['a', 'b', 'c']) manager.add_metadata_for_embedding_variable('test', metadata) expected_tensor = np.array([[1, 2], [3, 4], [5, 6]]) image1 = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) image2 = np.array([[[10, 20, 30], [40, 50, 60]], [[70, 80, 90], [100, 110, 120]]]) manager.add_embedding('emb', expected_tensor, metadata, [image1, image2], [2, 2]) fw = writer.FileWriter(self.log_dir, graph=g) fw.close() self._SetupWSGIApp() run_json = self._GetJson('/data/plugin/projector/runs') self.assertTrue(run_json) run = run_json[0] metadata_query = '/data/plugin/projector/metadata?run=%s&name=emb' % run metadata_tsv = self._Get(metadata_query).data self.assertEqual(metadata_tsv, b'a\nb\nc\n') unk_metadata_query = '/data/plugin/projector/metadata?run=%s&name=q' % run response = self._Get(unk_metadata_query) self.assertEqual(response.status_code, 400) tensor_query = '/data/plugin/projector/tensor?run=%s&name=emb' % run tensor_bytes = self._Get(tensor_query).data self._AssertTensorResponse(tensor_bytes, expected_tensor) unk_tensor_query = '/data/plugin/projector/tensor?run=%s&name=var1' % run response = self._Get(unk_tensor_query) self.assertEqual(response.status_code, 400) image_query = '/data/plugin/projector/sprite_image?run=%s&name=emb' % run image_bytes = self._Get(image_query).data with ops.Graph().as_default(): s = session.Session() image_array = image_ops.decode_png(image_bytes).eval( session=s).tolist() expected_sprite_image = [[[1, 2, 3], [4, 5, 6], [10, 20, 30], [40, 50, 60]], [[7, 8, 9], [10, 11, 12], [70, 80, 90], [100, 110, 120]], [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]] self.assertEqual(image_array, expected_sprite_image)
def log_graph(graph, name): """ Log the graph on Tensorboard. Args: graph: the tensorflow graph to be plotted on Tensorboard name: the name of the graph """ directory = os.path.join(autodist.const.DEFAULT_WORKING_DIR, "graphs") os.makedirs(directory, exist_ok=True) p = os.path.join(directory, name) writer.FileWriter(p, graph=graph) logging.debug('Graph summary written to: %s' % p)
def testNoAssetsProperSerializationOnDisk(self): logdir = self.get_temp_dir() plugin_dir = os.path.join(logdir, writer._PLUGINS_DIR, projector_plugin.ProjectorPluginAsset.plugin_name) with ops.Graph().as_default() as g: plugin_asset.get_plugin_asset(projector_plugin.ProjectorPluginAsset) fw = writer.FileWriter(logdir) fw.add_graph(g) with gfile.Open(os.path.join(plugin_dir, 'projector_config.pbtxt')) as f: content = f.read() self.assertEqual(content, '')
def testFileWriterWithSuffix(self): test_dir = self._CleanTestDir("test_suffix") sw = writer.FileWriter(test_dir, filename_suffix="_test_suffix") for _ in range(10): sw.add_summary( summary_pb2.Summary(value=[ summary_pb2.Summary.Value(tag="float_ten", simple_value=10.0) ]), 10) sw.close() sw.reopen() sw.close() event_filenames = glob.glob(os.path.join(test_dir, "event*")) for filename in event_filenames: self.assertTrue(filename.endswith("_test_suffix"))
def testEndpointsMetadataForVariableAssetsButNoCheckpoint(self): g = ops.Graph() with g.as_default(): manager = plugin_asset.get_plugin_asset( projector_plugin.ProjectorPluginAsset) metadata = projector_plugin.EmbeddingMetadata(3) metadata.add_column('labels', ['a', 'b', 'c']) manager.add_metadata_for_embedding_variable('test', metadata) fw = writer.FileWriter(self.log_dir, graph=g) fw.close() self._SetupWSGIApp() run_json = self._GetJson('/data/plugin/projector/runs') self.assertEqual(run_json, [])
def testPluginAssetSerialized(self): with ops.Graph().as_default() as g: plugin_asset.get_plugin_asset(ExamplePluginAsset) logdir = self.get_temp_dir() fw = writer.FileWriter(logdir) fw.add_graph(g) plugin_dir = os.path.join(logdir, writer._PLUGINS_DIR, "example") with gfile.Open(os.path.join(plugin_dir, "foo.txt"), "r") as f: content = f.read() self.assertEqual(content, "foo!") with gfile.Open(os.path.join(plugin_dir, "bar.txt"), "r") as f: content = f.read() self.assertEqual(content, "bar!")
def testSesssionArgument_callableProvider(self): logdir = self.get_temp_dir() setup_writer = summary_ops_v2.create_file_writer(logdir=logdir) with summary_ops_v2.always_record_summaries(), setup_writer.as_default( ): summary1 = summary_ops_v2.scalar("one", 0.0, step=0) summary2 = summary_ops_v2.scalar("two", 0.0, step=0) sess1 = session.Session() sess1.run(setup_writer.init()) sess1.run(summary1) sess1.run(setup_writer.flush()) time.sleep(1.1) # Ensure filename has a different timestamp sess2 = session.Session() sess2.run(setup_writer.init()) sess2.run(summary2) sess2.run(setup_writer.flush()) # Using get_default_session as session provider should make this FileWriter # send its summaries to the current default session's shared summary writer # resource (initializing it as needed). test_writer = writer.FileWriter(session=ops.get_default_session, logdir=logdir) with sess1.as_default(): test_writer.add_summary(self._createTaggedSummary("won"), 1) test_writer.flush() with sess2.as_default(): test_writer.add_summary(self._createTaggedSummary("too"), 1) test_writer.flush() event_paths = iter(sorted(glob.glob(os.path.join(logdir, "event*")))) # First file should have tags "one", "won" events = summary_iterator.summary_iterator(next(event_paths)) self.assertEqual("brain.Event:2", next(events).file_version) self.assertEqual("one", next(events).summary.value[0].tag) self.assertEqual("won", next(events).summary.value[0].tag) self.assertRaises(StopIteration, lambda: next(events)) # Second file should have tags "two", "too" events = summary_iterator.summary_iterator(next(event_paths)) self.assertEqual("brain.Event:2", next(events).file_version) self.assertEqual("two", next(events).summary.value[0].tag) self.assertEqual("too", next(events).summary.value[0].tag) self.assertRaises(StopIteration, lambda: next(events)) # No more files self.assertRaises(StopIteration, lambda: next(event_paths))
def testAddingSummariesFromSessionRunCalls(self): test_dir = self._CleanTestDir("global_step") sw = writer.FileWriter(test_dir) with self.test_session(): i = constant_op.constant(1, dtype=dtypes.int32, shape=[]) l = constant_op.constant(2, dtype=dtypes.int64, shape=[]) # Test the summary can be passed serialized. summ = summary_pb2.Summary( value=[summary_pb2.Summary.Value( tag="i", simple_value=1.0)]) sw.add_summary(summ.SerializeToString(), i.eval()) sw.add_summary( summary_pb2.Summary( value=[summary_pb2.Summary.Value( tag="l", simple_value=2.0)]), l.eval()) sw.close() rr = self._EventsReader(test_dir) # File_version. ev = next(rr) self.assertTrue(ev) self._assertRecent(ev.wall_time) self.assertEquals("brain.Event:2", ev.file_version) # Summary passed serialized. ev = next(rr) self.assertTrue(ev) self._assertRecent(ev.wall_time) self.assertEquals(1, ev.step) self.assertProtoEquals(""" value { tag: 'i' simple_value: 1.0 } """, ev.summary) # Summary passed as SummaryObject. ev = next(rr) self.assertTrue(ev) self._assertRecent(ev.wall_time) self.assertEquals(2, ev.step) self.assertProtoEquals(""" value { tag: 'l' simple_value: 2.0 } """, ev.summary) # We should be done. self.assertRaises(StopIteration, lambda: next(rr))
def testSpriteImageUnknownName(self): self._GenerateProjectorTestData() g = ops.Graph() with g.as_default(): manager = plugin_asset.get_plugin_asset( projector_plugin.ProjectorPluginAsset) image1 = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) image2 = np.array([[[10, 20, 30], [40, 50, 60]], [[70, 80, 90], [100, 110, 120]]]) manager.add_metadata_for_embedding_variable( 'var1', thumbnails=[image1, image2], thumbnail_dim=[2, 2]) fw = writer.FileWriter(self.log_dir, graph=g) fw.close() self._SetupWSGIApp() q = '/data/plugin/projector/sprite_image?run=.&name=unknown' response = self._Get(q) self.assertEqual(response.status_code, 400)
def begin(self): if self._summary_writer is None and self._output_dir: self._summary_writer = writer.FileWriter( self._output_dir, filename_suffix="", session=ops.get_default_session) # Designate the first SummarySaverHook to call begin() as the "primary" # hook; it will control writing of v2 summaries via a placeholder bool. collection = ops.get_collection_ref( self._SUMMARY_PLACEHOLDER_COLLECTION) if collection: self._placeholder = collection[0] collection[:] = [] self._current_step = None self._global_step_tensor = training_util.get_or_create_global_step() if self._global_step_tensor is None: raise RuntimeError( "Global step should be created to use SummarySaverHook.")
def _set_summary_dir(self, model_dir): """Sets the summary directory to be model_dir/profile_logger.summary.""" if model_dir is None: self._summary_dir = None self._summary_writer = None logging.warning('profile_logger: model_dir is None.' 'So nowhere to write summaries') return self._summary_dir = model_dir + '/profile_logger.summary' try: self._summary_writer = writer.FileWriter(self._summary_dir) logging.info('profile_logger(): set the summary directory to %s', self._summary_dir) except Exception: # pylint: disable=broad-except logging.warning('profile_logger(): failed to create %s', self._summary_dir) self._summary_dir = None self._summary_writer = None
def testVisualizeEmbeddings(self): # Create a dummy configuration. config = projector_config_pb2.ProjectorConfig() config.model_checkpoint_path = 'test' emb1 = config.embeddings.add() emb1.tensor_name = 'tensor1' emb1.metadata_path = 'metadata1' # Call the API method to save the configuration to a temporary dir. temp_dir = self.get_temp_dir() self.addCleanup(shutil.rmtree, temp_dir) writer = writer_lib.FileWriter(temp_dir) projector.visualize_embeddings(writer, config) # Read the configuratin from disk and make sure it matches the original. with gfile.GFile(os.path.join(temp_dir, 'projector_config.pbtxt')) as f: config2 = projector_config_pb2.ProjectorConfig() text_format.Parse(f.read(), config2) self.assertEqual(config, config2)
def _set_summary_dir(self, model_dir): """Sets the summary directory to be model_dir.""" if model_dir is None: self._summary_dir = None self._summary_writer = None logging.warning('profile_logger: model_dir is None.' 'So nowhere to write summaries') return self._summary_dir = os.path.join(model_dir, 'profile') try: self._summary_writer = writer.FileWriter( logdir=self._summary_dir, filename_suffix='.profile_logger') logging.info('profile_logger(): set the summary directory to %s', self._summary_dir) except Exception: # pylint: disable=broad-except logging.warning('profile_logger(): failed to create %s', self._summary_dir) self._summary_dir = None self._summary_writer = None
def testCloseAndReopen(self): test_dir = self._CleanTestDir("close_and_reopen") sw = writer.FileWriter(test_dir) sw.add_session_log(event_pb2.SessionLog(status=SessionLog.START), 1) sw.close() # Sleep at least one second to make sure we get a new event file name. time.sleep(1.2) sw.reopen() sw.add_session_log(event_pb2.SessionLog(status=SessionLog.START), 2) sw.close() # We should now have 2 events files. event_paths = sorted(glob.glob(os.path.join(test_dir, "event*"))) self.assertEquals(2, len(event_paths)) # Check the first file contents. rr = summary_iterator.summary_iterator(event_paths[0]) # The first event should list the file_version. ev = next(rr) self._assertRecent(ev.wall_time) self.assertEquals("brain.Event:2", ev.file_version) # The next event should be the START message. ev = next(rr) self._assertRecent(ev.wall_time) self.assertEquals(1, ev.step) self.assertEquals(SessionLog.START, ev.session_log.status) # We should be done. self.assertRaises(StopIteration, lambda: next(rr)) # Check the second file contents. rr = summary_iterator.summary_iterator(event_paths[1]) # The first event should list the file_version. ev = next(rr) self._assertRecent(ev.wall_time) self.assertEquals("brain.Event:2", ev.file_version) # The next event should be the START message. ev = next(rr) self._assertRecent(ev.wall_time) self.assertEquals(2, ev.step) self.assertEquals(SessionLog.START, ev.session_log.status) # We should be done. self.assertRaises(StopIteration, lambda: next(rr))
def setUp(self): self._work_dir = tempfile.mkdtemp(dir=self.get_temp_dir()) self._sw = writer.FileWriter(self._work_dir) tensorboard_logging.set_summary_writer(self._sw) self.addCleanup(shutil.rmtree, self._work_dir) # Stop the clock to avoid test flakiness. now = time.time() time._real_time = time.time time.time = lambda: now # Mock out logging calls so we can verify that the right number of messages # get logged. self.logged_message_count = 0 self._actual_log = logging.log def mockLog(*args, **kwargs): self.logged_message_count += 1 self._actual_log(*args, **kwargs) logging.log = mockLog
def testGraphFromMetaGraphBecomesAvailable(self): """Test accumulator by writing values and then reading them.""" directory = os.path.join(self.get_temp_dir(), 'metagraph_test_values_dir') if gfile.IsDirectory(directory): gfile.DeleteRecursively(directory) gfile.MkDir(directory) writer = writer_lib.FileWriter(directory, max_queue=100) with ops.Graph().as_default() as graph: _ = constant_op.constant([2.0, 1.0]) # Add a graph to the summary writer. meta_graph_def = saver.export_meta_graph(graph_def=graph.as_graph_def( add_shapes=True)) writer.add_meta_graph(meta_graph_def) writer.flush() # Verify that we can load those events properly acc = ea.EventAccumulator(directory) acc.Reload() self.assertTagsEqual( acc.Tags(), { ea.IMAGES: [], ea.AUDIO: [], ea.SCALARS: [], ea.HISTOGRAMS: [], ea.COMPRESSED_HISTOGRAMS: [], ea.GRAPH: True, ea.META_GRAPH: True, ea.RUN_METADATA: [] }) self.assertProtoEquals(graph.as_graph_def(add_shapes=True), acc.Graph()) self.assertProtoEquals(meta_graph_def, acc.MetaGraph())