Operations for writing summary data, for use in analysis and visualization.
The tf.summary
module provides APIs for writing summary data. This data can be visualized in TensorBoard, the visualization toolkit that comes with TensorFlow. See the TensorBoard website for more detailed tutorials about how to use these APIs, or some quick examples below.
Example usage with eager execution, the default in TF 2.0:
writer = tf.summary.create_file_writer("/tmp/mylogs") with writer.as_default(): for step in range(100): # other model code would go here tf.summary.scalar("my_metric", 0.5, step=step) writer.flush()
Example usage with tf.function
graph execution:
writer = tf.summary.create_file_writer("/tmp/mylogs") @tf.function def my_func(step): # other model code would go here with writer.as_default(): tf.summary.scalar("my_metric", 0.5, step=step) for step in range(100): my_func(step) writer.flush()
Example usage with legacy TF 1.x graph execution:
with tf.compat.v1.Graph().as_default(): step = tf.Variable(0, dtype=tf.int64) step_update = step.assign_add(1) writer = tf.summary.create_file_writer("/tmp/mylogs") with writer.as_default(): tf.summary.scalar("my_metric", 0.5, step=step) all_summary_ops = tf.compat.v1.summary.all_v2_summary_ops() writer_flush = writer.flush() sess = tf.compat.v1.Session() sess.run([writer.init(), step.initializer]) for i in range(100): sess.run(all_summary_ops) sess.run(step_update) sess.run(writer_flush)
experimental
module: Public API for tf.summary.experimental namespace.
class SummaryWriter
: Interface representing a stateful summary writer object.
audio(...)
: Write an audio summary.
create_file_writer(...)
: Creates a summary file writer for the given log directory.
create_noop_writer(...)
: Returns a summary writer that does nothing.
flush(...)
: Forces summary writer to send any buffered data to storage.
histogram(...)
: Write a histogram summary.
image(...)
: Write an image summary.
record_if(...)
: Sets summary recording on or off per the provided boolean value.
scalar(...)
: Write a scalar summary.
text(...)
: Write a text summary.
trace_export(...)
: Stops and exports the active trace as a Summary and/or profile file.
trace_off(...)
: Stops the current trace and discards any collected information.
trace_on(...)
: Starts a trace to record computation graphs and profiling information.
write(...)
: Writes a generic summary to the default SummaryWriter if one exists.
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/compat/v2/summary