Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 字符串类型特征的TensorFlow输入数据协议缓冲区(tf.train.Example)类型错误_Python_Tensorflow - Fatal编程技术网

Python 字符串类型特征的TensorFlow输入数据协议缓冲区(tf.train.Example)类型错误

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

我正试图按照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: '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])