今天学习tensorflow的时候,发现如下报错
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.For reference, the tensor object was Tensor("strided_slice:0", shape=(), dtype=float32) which was passed to the feed with key Tensor("X_1:0", dtype=float32).
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.For reference, the tensor object was Tensor("strided_slice:0", shape=(), dtype=float32) which was passed to the feed with key Tensor("X_1:0", dtype=float32).
我写的代码中关键句如下:
#为训练数据申明Tensorflow占位符
X_train = tf.linspace(0.,1.,101)#这里是一个tensor类型
Y_train = X_train*3+0.02
#启动计算图
sess.run([optimizer, loss],feed_dict = {X:X_train[i], Y:Y_train[i]})
首先我申明了一个占位符,然后在Session中给它喂值,喂进去的值是一个tensor类型的数据。
报错的原因也很简单,他说feed进去的值不能是tensor类型,它可以是:python中的向量、字符串、列表或者是numpy中的n维数组。
将程序修改为
X_train = np.linspace(0.,1.,101)