當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。