Module: tf.summary用法

Module: tf.summary:用于编写摘要数据的操作,用于分析和可视化。

tf.summary模块提供用于编写​​摘要数据的API。可以在TensorBoard(TensorFlow随附的可视化工具包)中可视化此数据。

急切执行的示例用法,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()

tf.function图形执行的示例用法:

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()

传统TF 1.x图形执行的用法示例:

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)

Modules:

experimental模块:tf.summary.experimental命名空间的公共API。

Classes:

class SummaryWriter:表示状态摘要编写器对象的接口。

Functions:

audio(...):编写音频摘要。

create_file_writer(...):为给定的日志目录创建摘要文件编写器。

create_noop_writer(...):返回不执行任何操作的摘要编写器。

flush(...):强制摘要编写器将所有缓冲的数据发送到存储。

histogram(...):编写直方图摘要。

image(...):编写图像摘要。

record_if(...):根据提供的布尔值设置是否打开摘要记录。

scalar(...):编写标量摘要。

should_record_summaries(...):返回布尔张量,如果应记录摘要,则为true。

text(...):编写文本摘要。

trace_export(...):停止活动的跟踪并将其导出为摘要和/或配置文件。

trace_off(...):停止当前跟踪并丢弃所有收集的信息。

trace_on(...):开始跟踪以记录计算图和性能分析信息。

write(...):将通用摘要写入默认的SummaryWriter(如果存在)。

猜你喜欢

转载自blog.csdn.net/qq_36201400/article/details/108281343