close

How to inspect a Tensorflow .tfrecord file?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to inspect a Tensorflow .tfrecord file in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to inspect a Tensorflow .tfrecord file?

  1. How to inspect a Tensorflow .tfrecord file?

    Found it!
    import tensorflow as tf for example in tf.python_io.tf_record_iterator("data/foobar.tfrecord"):

  2. inspect a Tensorflow .tfrecord file

    Found it!
    import tensorflow as tf for example in tf.python_io.tf_record_iterator("data/foobar.tfrecord"):

Method 1

Found it!

import tensorflow as tf

for example in tf.python_io.tf_record_iterator("data/foobar.tfrecord"):
    print(tf.train.Example.FromString(example))

You can also add:

from google.protobuf.json_format import MessageToJson
...
jsonMessage = MessageToJson(tf.train.Example.FromString(example))

Method 2

Above solutions didn’t work for me so for TF 2.0 use this:

import tensorflow as tf 
raw_dataset = tf.data.TFRecordDataset("path-to-file")

for raw_record in raw_dataset.take(1):
    example = tf.train.Example()
    example.ParseFromString(raw_record.numpy())
    print(example)

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read