我是Tensorflow的新手。我已经通过这个例子进行了MNIST训练
steps = 5000
with tf.Session() as sess:
sess.run(init)
for i in range(steps):
batch_x , batch_y = mnist.train.next_batch(50)
sess.run(train,feed_dict={x:batch_x,y_true:batch_y,hold_prob:0.5})
# PRINT OUT A MESSAGE EVERY 100 STEPS
if i%100 == 0:
print('Currently on step {}'.format(i))
print('Accuracy is:')
# Test the Train Model
matches = tf.equal(tf.argmax(y_pred,1),tf.argmax(y_true,1))
acc = tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict=
{x:mnist.test.images,y_true:mnist.test.labels,hold_prob:1.0}))
print('\n')现在我想用这个模型做预测。我用下面这几行代码打开并处理图像。
image = cv2.imread("Untitled.jpg")
image = np.multiply(image, 1.0/255.0)
images=tf.reshape(image,[-1,28,28,1])当我使用这个的时候:
feed_dict1 = {x: images}
classification = sess.run(y_pred, feed_dict1)
print (classification)它返回此错误。
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.发布于 2018-02-18 10:31:30
您尝试将tf-object添加到占位符中:
images = tf.reshape(image,[-1,28,28,1])但是您不能这样做,因为占位符需要数字,例如np.array。所以使用numpy.reshape而不是tf.reshape。第二个是你可以在会话中使用的。例如,您可以将平面数组输入到占位符中,然后在会话中创建一个节点,该节点将此数组重塑为2D矩阵。
https://stackoverflow.com/questions/47847423
复制相似问题