报错代码:
with tf.Session() as sess:sess.run(init_op)for i in range(self.epoch_num):batch_images, batch_labels = mnist.train.next_batch(self.batch_size)batch_images = tf.reshape(tensor=batch_images, shape=[self.batch_size, 28, 28, 1])batch_images = tf.image.resize_images(images=batch_images,size=(32,32))print("images shape:{}".format(batch_images.shape))print("labels shape:{}".format(batch_labels.shape))accuracy = sess.run(train_op, feed_dict={images_holder:batch_images, labels_holder:batch_labels})print(accuracy)
报错信息:
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("resize_images/ResizeBilinear:0", shape=(100, 32, 32, 1), dtype=float32) which was passed to the feed with key Tensor("x:0", shape=(100, 32, 32, 1), dtype=float32).
报错提示已经很明显了,就是喂给训练操作的数据不能是张量,只能是 scalars, strings, lists, numpy ndarrays, or TensorHandles
解决方法:
在喂给训练操作的张量后面加 .eval(),将张量操作算出来的结果喂给训练操作就正常了
accuracy = sess.run(train_op, feed_dict={images_holder:batch_images.eval(), labels_holder:batch_labels})