TransWikia.com

TFRecord handling

Data Science Asked by BiologistAtHome on April 9, 2021

This is my first time encountering the TFRecord format and the documentation on it seems a little sparse. I was able to find the official walkthrough from TF but it’s not getting me all the way there.

feature_description = {
     "image/class/text" : tf.io.VarLenFeature(tf.string),
     "image/colorspace" : tf.io.VarLenFeature(tf.string),
     "image/encoded" : tf.io.VarLenFeature(tf.string),
     "image/filename" : tf.io.VarLenFeature(tf.string),
     "image/format" : tf.io.VarLenFeature(tf.string),
     "image/height" : tf.io.VarLenFeature(tf.int64),
     "image/id" : tf.io.VarLenFeature(tf.int64),
     "image/width" : tf.io.VarLenFeature(tf.int64)}

 def _parse_image_function(proto):
     # Parse the input tf.train.Example proto using the dictionary above.
     return tf.io.parse_single_example(proto, feature_description)

 parsed_image_dataset = raw_image_dataset.map(_parse_image_function)
 for parsed_record in parsed_image_dataset.take(4):
      print(parsed_record)

Outputs a bunch of addresses in the RAM(?):

{'image/class/text': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093adfe80>, 'image/colorspace': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093af80f0>, 'image/encoded': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093af8048>, 'image/filename': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093af8128>, 'image/format': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093af8160>, 'image/height': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093af8198>, 'image/id': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093af81d0>, 'image/width': <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f9093af8208>}
 ...

Which feels like I’m really close – like I just need to get those values but I’ve clearly missed some step the walkthrough doesn’t include (or highlight?)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP