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

问题描述 投票:1回答:2

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

tensorflow tensorboard tensorflow2.0
2个回答
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:
  ...

希望这会有所帮助。

种类


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))
© www.soinside.com 2019 - 2024. All rights reserved.