我正在使用MNIST数据集,我有一个错误,即" TypeError:Feed的值不能是tf.Tensor对象。可接受的Feed值包括Python标量,字符串,列表,numpy ndarrays或TensorHandles。"。
我是tensorflow的新手,如果你能帮助我解决它,我将非常感激。我的代码如下:
import tensorflow as tf
tf.reset_default_graph()
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
x = tf.placeholder(tf.float32, [None, 2704])
#layer 1
W = tf.get_variable("weights", shape=[2704, 10],
initializer=tf.random_normal_initializer())
b = tf.get_variable("bias", shape=[10],
initializer=tf.random_normal_initializer())
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y),
reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.2).minimize(cross_entropy)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
batch_size=50
for _ in range(10000):
batch_img, batch_label = mnist.train.next_batch(batch_size)
imgs = batch_img.reshape((-1, 28, 28, 1))
resized_images = tf.image.resize_images(imgs, [52, 52])
print(resized_images.shape)
print(tf.reshape(resized_images,[-1,2704]).shape)
image=tf.reshape(resized_images,[-1,2704])
sess.run(train_step, feed_dict={x:image, y_: batch_label})
非常感谢您的帮助。