计算机视觉——【模型训练】bug调试 typeError:The value of a feed cannot be a tf.Tensor object.

系统环境

win10 x64
Anaconda3 + tensorflow-gpu 1.8.0

问题描述

在搭建一个神经网络时,通过MNIST为预测试数据集进行测试,在启动session后,显示‘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…’

简单理解就是,数据的输入和要求格式不同

问题解决

placeholder在定义时要求的输入数据的格式,而经过tf.reshape(tensorflow.reshape)或者tf的变换后,返回的数据均为Tensor,对于要求输入为ndarray的函数或方法就会报错;

  1. 将tf.reshape换做numpy.reshape
  2. 或将Tensor转换为ndarray数据格式(上一种方法更为便利)

tips:
tensorflow虽为支持python的深度学习框架,但是Tensor和ndarray是两种完全不同的数据格式,两者不通用但是可以互相转化

发布了47 篇原创文章 · 获赞 55 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/u011106767/article/details/94406483
今日推荐