Parsing

Parse data from serialized protocol buffers.

Chapter Goals:

  • Learn how to parse a serialized protocol buffer
  • Understand how feature data is represented in TensorFlow
  • Implement a function that parses a serialized protocol buffer

A. Feature parsing

After creating an Example spec, it can be used to parse serialized protocol buffers that are read from a TFRecords file. Specifically, we use the Example spec as an argument to the tf.io.parse_single_example function, which converts a serialized protocol buffer into a usable feature dictionary.

Press + to interact
import tensorflow as tf
print(example_spec)
print(repr(ex))
parsed = tf.io.parse_single_example(
ex.SerializeToString(), example_spec)
print(repr(parsed))

You’ll notice that the output of tf.io.parse_single_example ...