Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading TF2 summary file with tf.data.TFRecordDataset

In TF1, i could use summary_iterator to read summary files. But now, it will throw a warning

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)`

So i'm wondering how to use tf.data.TFRecordDataset(path) to read tfevent files generated by TF2.

like image 914
fish_tree Avatar asked Oct 05 '19 13:10

fish_tree


People also ask

What does TF Summary do?

The tf. summary module provides APIs for writing summary data. This data can be visualized in TensorBoard, the visualization toolkit that comes with TensorFlow. See the TensorBoard website for more detailed tutorials about how to use these APIs, or some quick examples below.

What does TF data dataset From_tensor_slices do?

Dataset. from_tensor_slices() method, we can get the slices of an array in the form of objects by using tf. data.

What is a TFRecord file?

The TFRecord format is a simple format for storing a sequence of binary records. Protocol buffers are a cross-platform, cross-language library for efficient serialization of structured data. Protocol messages are defined by . proto files, these are often the easiest way to understand a message type.


1 Answers

Actually, this works for me

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))
like image 110
fish_tree Avatar answered Oct 03 '22 08:10

fish_tree