如何在Python中为Tensorflow预测设置图像形状?

如何在Python中为Tensorflow预测设置图像形状?,python,tensorflow,Python,Tensorflow,我正在处理以下错误: ValueError: Cannot feed value of shape (32, 32, 3) for Tensor 'Placeholder:0', which has shape '(?, 32, 32, 3)' 占位符设置为:x=tf.placeholder(tf.float32,(None,32,32,3)) 并且图像(在运行打印(img1.shape)时)具有输出:(32,32,3) 运行时如何更新要对齐的图像:print(sess.run(correct

我正在处理以下错误:

ValueError: Cannot feed value of shape (32, 32, 3) for Tensor 'Placeholder:0', which has shape '(?, 32, 32, 3)'
占位符设置为:
x=tf.placeholder(tf.float32,(None,32,32,3))

并且图像(在运行
打印(img1.shape)
时)具有输出:
(32,32,3)


运行时如何更新要对齐的图像:
print(sess.run(correct_prediction,feed_dict={x:img1}))
程序中的占位符
x
表示32x32(大概)RGB图像的批处理,预测将在一步中计算出来。如果要计算单个图像上的预测值,即形状数组
(32,32,3)
,则必须对其进行整形,使其具有额外的前导尺寸。有很多方法可以做到这一点,但有一种很好的方法:

 img1 = ...                             # Array of shape (32, 32, 3)
 img1_as_batch = img1[np.newaxis, ...]  # Array of shape (1, 32, 32, 3)

 print(sess.run(correct_prediction, feed_dict={x: img1_as_batch}))

将img改为(1,32,32,3)谢谢!有什么建议吗?img.重塑((1,32,32,3))谢谢,就这样!