Python 字符串类型特征的TensorFlow输入数据协议缓冲区(tf.train.Example)类型错误
我正试图按照tensorflow的方法对我的数据进行编码。 我有一个字符串值,我想传递给Python 字符串类型特征的TensorFlow输入数据协议缓冲区(tf.train.Example)类型错误,python,tensorflow,Python,Tensorflow,我正试图按照tensorflow的方法对我的数据进行编码。 我有一个字符串值,我想传递给示例类的功能属性,我正在使用以下代码: import tensorflow as tf tf_example = tf.train.Example() s1 = "sample string 1" tf_example.features.feature['str1'].bytes_list.value.extend([s1]) 但是,我得到一个错误,它期望的是字节而不是str: TypeError: 'sa
示例
类的功能
属性,我正在使用以下代码:
import tensorflow as tf
tf_example = tf.train.Example()
s1 = "sample string 1"
tf_example.features.feature['str1'].bytes_list.value.extend([s1])
但是,我得到一个错误,它期望的是字节
而不是str
:
TypeError: 'sample string 1' has type <class 'str'>, but expected one of: ((<class 'bytes'>,),)
TypeError:“示例字符串1”具有类型,但应为以下类型之一:(,),)
我遗漏了什么?似乎他们希望
s1
是一个字节字符串,因此您需要在“
之前添加b
:
import tensorflow as tf
tf_example = tf.train.Example()
s1 = b"sample string 1"
tf_example.features.feature['str1'].bytes_list.value.extend([s1])