Decoding TFRecord and reconstructing the image
In the previous section, we learned how to write a .jpg
image into a TFRecord
dataset. Now we are going to see how to read it back and display it. An important requirement is that you must know the feature structure of the TFRecord
protobuf as indicated by its keys. The feature structure is the same as the feature description used to build the TFRecord
in the previous section. In other words, in the same way as a raw image was structured into a tf.Example
protobuf with a defined feature description, we can use that feature description to parse or reconstruct the image using the same knowledge stored in the feature description:
- Read
TFRecord
back from the path where it is stored:read_back_tfrecord = tf.data.TFRecordDataset('tfrecords-collection/maldives-1.tfrecord')
- Create a dictionary to specify the keys and values in
TFRecord
, and use it to parse all elements in theTFRecord
dataset:# Create a dictionary describing...