首页 > 解决方案 > 使用 tf.data.TFRecordDataset 读取 TF2 摘要文件

问题描述

在 TF1 中,我可以summary_iterator用来读取摘要文件。但是现在,它会发出警告

WARNING:tensorflow: tf_record_iterator (from tensorflow.python.lib.io.tf_record) is deprecated and will be removed in a future version.
Instructions for updating:
Use eager execution and: 
`tf.data.TFRecordDataset(path)`

所以我想知道如何使用tf.data.TFRecordDataset(path)来读取 TF2 生成的 tfevent 文件。

标签: tensorflowtensorboardtensorflow2.0

解决方案


实际上,这对我有用

from tensorflow.core.util import event_pb2

serialized_examples = tf.data.TFRecordDataset(path)
for serialized_example in serialized_examples:
    event = event_pb2.Event.FromString(serialized_example.numpy())
    for value in event.summary.value:
        t = tf.make_ndarray(value.tensor)
        print(value.tag, event.step, t, type(t))

推荐阅读