Help protect the Great Barrier Reef with TensorFlow on Kaggle Join Challenge

tf.compat.v1.summary.FileWriter

Writes Summary protocol buffers to event files.

Migrate to TF2

This API is not compatible with eager execution or tf.function. To migrate to TF2, please use tf.summary.create_file_writer instead for summary management. To specify the summary step, you can manage the context with tf.summary.SummaryWriter, which is returned by tf.summary.create_file_writer(). Or, you can also use the step argument of summary functions such as tf.summary.histogram. See the usage example shown below.

For a comprehensive tf.summary migration guide, please follow Migrating tf.summary usage to TF 2.0.

How to Map Arguments

TF1 Arg Name TF2 Arg Name Note
logdir logdir -
graph Not supported -
max_queue max_queue -
flush_secs flush_millis The unit of time is changed from seconds to milliseconds.
graph_def Not supported -
filename_suffix filename_suffix -
name name -

TF1 & TF2 Usage Example

TF1:

dist = tf.compat.v1.placeholder(tf.float32, [100])
tf.compat.v1.summary.histogram(name="distribution", values=dist)
writer = tf.compat.v1.summary.FileWriter("/tmp/tf1_summary_example")
summaries = tf.compat.v1.summary.merge_all()

sess = tf.compat.v1.Session()
for step in range(100):
  mean_moving_normal = np.random.normal(loc=step, scale=1, size=[100])
  summ = sess.run(summaries, feed_dict={dist: mean_moving_normal})
  writer.add_summary(summ, global_step=step)

TF2:

writer = tf.summary.create_file_writer("/tmp/tf2_summary_example")
for step in range(100):
  mean_moving_normal = np.random.normal(loc=step, scale=1, size=[100])
  with writer.as_default(step=step):
    tf.summary.histogram(name='distribution', data=mean_moving_normal)

Description

The FileWriter class provides a mechanism to create an event file in a given directory and add summaries and events to it. The class updates the file contents asynchronously. This allows a training program to call methods to add data to the file directly from the training loop, without slowing down training.

When constructed with a tf.compat.v1.Session parameter, a FileWriter instead forms a compatibility layer over new graph-based summaries to facilitate the use of new summary writing with pre-existing code that expects a FileWriter instance.

This class is not thread-safe.

logdir A string. Directory where event file will be written.
graph A Graph object, such as sess.graph.
max_queue Integer. Size of the queue for pending events and summaries.
flush_secs Number. How often, in seconds, to flush the pending events and summaries to disk.
graph_def DEPRECATED: Use the graph argument instead.
filename_suffix A string. Every event file's name is suffixed with suffix.
session A tf.compat.v1.Session object. See details above.

RuntimeError If called with eager execution enabled.

Methods

add_event

View source

Adds an event to the event file.

Args
event An Event protocol buffer.

add_graph

View source

Adds a Graph to the event file.

The graph described by the protocol buffer will be displayed by TensorBoard. Most users pass a graph in the constructor instead.

Args
graph A Graph object, such as sess.graph.
global_step Number. Optional global step counter to record with the graph.
graph_def DEPRECATED. Use the graph parameter instead.

Raises
ValueError If both graph and graph_def are passed to the method.

add_meta_graph

View source

Adds a MetaGraphDef to the event file.

The MetaGraphDef allows running the given graph via saver.import_meta_graph().