Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
How to inspect a Tensorflow .tfrecord file?

I have a .tfrecord but I don't know how it is structured. How can I inspect the schema to understand what the .tfrecord file contains?

All Stackoverflow answers or documentation seem to assume I know the structure of the file.

reader = tf.TFRecordReader()
file = tf.train.string_input_producer("record.tfrecord")
_, serialized_record = reader.read(file)

...HOW TO INSPECT serialized_record...
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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))
over 4 years ago · Santiago Trujillo Report

0

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)

https://www.tensorflow.org/tutorials/load_data/tfrecord#reading_a_tfrecord_file_2

over 4 years ago · Santiago Trujillo Report

0

If your .tftrecord contains SequenceExample, the accepted answer won't show you everything. You can use:

import tensorflow as tf

for example in tf.python_io.tf_record_iterator("data/foobar.tfrecord"):
    result = tf.train.SequenceExample.FromString(example)
    break
print(result)

This will show you the content of the first example.

Then you can also inspect individual Features using their keys:

result.context.feature["foo_key"]

And for FeatureLists:

result.feature_lists.feature_list["bar_key"]
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!