当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python tf.compat.v1.train.summary_iterator用法及代码示例

返回用于从事件文件中读取 Event 协议缓冲区的迭代器。

用法

tf.compat.v1.train.summary_iterator(
    path
)

参数

  • path SummaryWriter 创建的事件文件的路径。

返回

  • 产生 Event 协议缓冲区的迭代器

您可以使用此函数读取写入事件文件的事件。它返回一个 Python 迭代器,它产生 Event 协议缓冲区。

示例:打印事件文件的内容。

for e in tf.compat.v1.train.summary_iterator(path to events file):
    print(e)

示例:打印选定的汇总值。

# This example supposes that the events file contains summaries with a
# summary value tag 'loss'.  These could have been added by calling
# `add_summary()`, passing the output of a scalar summary op created with
# with:`tf.compat.v1.summary.scalar('loss', loss_tensor)`.
for e in tf.compat.v1.train.summary_iterator(path to events file):
    for v in e.summary.value:
        if v.tag == 'loss':
            print(v.simple_value)

示例:不断检查新的汇总值。

summaries = tf.compat.v1.train.summary_iterator(path to events file)
while True:
  for e in summaries:
      for v in e.summary.value:
          if v.tag == 'loss':
              print(v.simple_value)
  # Wait for a bit before checking the file for any new events
  time.sleep(wait time)

有关其属性的更多信息,请参阅 Event 和 Summary 的协议缓冲区定义。

相关用法


注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.train.summary_iterator。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。