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...
TFRecordReader() file = tf. train. string_input_producer("record. tfrecord") _, serialized_record = reader.
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.
Ideally, you should shard the data to ~10N files, as long as ~X/(10N) is 10+ MBs (and ideally 100+ MBs).
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))
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With