使用tf.data.TFRecordDataset读取TF2摘要文件

时间:2019-10-05 13:30:47

标签: tensorflow tensorboard tensorflow2.0

在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文件。

2 个答案:

答案 0 :(得分:0)

我真的不知道您要达到什么目的,但是如果TFEvent文件是常规的TFRecord文件,则可以通过这种方式使用新的API。

event_files = tf.data.Dataset.list_files("./outputs/events.out.tfevents*")
serialized_examples = tf.data.TFRecordDataset(events_files)
for serialized_example in serialized_examples:
  ...

希望这会有所帮助。

种类

答案 1 :(得分: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))