I have the following method which is supposed to decode samples from serialized TFRecordDataset:
def decode_example(self, serialized_example):
"""Return a dict of Tensors from a serialized tensorflow.Example."""
data_fields, data_items_to_decoders = self.example_reading_spec()
# Necessary to rejoin examples in the correct order with the Cloud ML Engine
# batch prediction API.
data_fields['batch_prediction_key'] = tf.io.FixedLenFeature([1], tf.int64, 0)
if data_items_to_decoders is None:
data_items_to_decoders = {
field: tf.contrib.slim.tfexample_decoder.Tensor(field)
for field in data_fields
}
decoder = tf.contrib.slim.tfexample_decoder.TFExampleDecoder(data_fields, data_items_to_decoders)
decode_items = list(sorted(data_items_to_decoders))
decoded = decoder.decode(serialized_example, items=decode_items)
return dict(zip(decode_items, decoded))
However, this does not work under Tensorflow 2.
tf.contrib does not exist anymore and I do not find anything I can use to decode these examples.
I cannot even find the TFExampleDecoder after installing tensorflow-data-validation.
Any idea what's wrong there and/or how I can decode my examples?