TensorFlow 报错 TypeError: The value of a feed cannot be a tf.Tensor object

报错代码:

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})

 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

csdn-WJW

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值