Skip to content Skip to sidebar Skip to footer

How To Get Original String Data Back From Tfrecorddata

I followed Tensorflow guide to save my string data using: def _create_string_feature(values): return tf.train.Feature(bytes_list=tf.train.BytesList(value=[values.encode('utf-8

Solution 1:

This will convert a BytesList or bytes_list string object to a string:

my_bytes_list_object.value[0].decode()

Or, in the case one is extracting the string from a TFRecord Example object:

my_example.features.feature['MyFeatureName'].bytes_list.value[0].decode()

From what I can see, bytes_list returns a BytesList object, from which we can read the value field. This will return a RepeatedScalarContainer, which operates like a simple list object. In fact, if you wrap it with the list() operation it will convert it to a list. However, instead we can just access it as if it were a list and use [0] to get the zeroth item. The returned item is a bytes array, which can be converted to a standard str object with the decode() method.

Post a Comment for "How To Get Original String Data Back From Tfrecorddata"