用Tensorflow对二维图像做神经网络训练的时候,将二维数据转化为一维数据的时候,常常出现如下等错误:
ValueError: Cannot feed value of shape (10,X, X) for Tensor ‘Placeholder:0’, which has shape ‘(?, XX)’
ValueError: Cannot feed value of shape (X, X) for Tensor ‘Placeholder:0’, which has shape ‘(?, X)’
ValueError: Cannot feed value of shape (X,) for Tensor ‘Placeholder:0’, which has shape ‘(?, X)’
错误的含义是TensorFlow无法为Tensor’占位符:0’提供形状值。
placeholder是TensorFlow的占位符节点,由placeholder方法创建,也是一种常量,是由用户在调用run方法是传递的,也可以将placeholder理解为一种形参。本例创建如下:
#每张图片共有120*160=19200个像素点
x=tf.placeholder(tf.float32,[None,19200],name="X")
#0-4一共5个数字=>5个类别
y=tf.placeholder(tf.float32,[None,5],name="Y")
for epoch in range(train_epochs):
for batch in range(total_batch):
xs, ys = get_train_batch(batch,batch_size) # 读取批次数据
#print(xs.shape)
#pri