Reputation: 11160
I am trying to encode my data as tf.train.Example according to tensorflow's tutorial.
I have a string value that I want to pass to the Features
property of the Example
class and I am using the following code:
import tensorflow as tf
tf_example = tf.train.Example()
s1 = "sample string 1"
tf_example.features.feature['str1'].bytes_list.value.extend([s1])
However, I get the error that it is expecting bytes
not str
:
TypeError: 'sample string 1' has type <class 'str'>, but expected one of: ((<class 'bytes'>,),)
What am I missing?
Upvotes: 1
Views: 664
Reputation: 19634
It seems that they expect s1
to be a byte string, so you need to add b
before the "
:
import tensorflow as tf
tf_example = tf.train.Example()
s1 = b"sample string 1"
tf_example.features.feature['str1'].bytes_list.value.extend([s1])
Upvotes: 2