HeJ小鼠,
在我的IRIS数据集的多类神经网络的最后一步中,我正在执行以下代码:
steps = 2500
with tf.Session() as sess:
sess.run(init)
for i in range(steps):
sess.run(train,feed_dict={X_data:X_train,y_target:y_train})
# PRINT OUT A MESSAGE EVERY 100 STEPS
if i%500 == 0:
print('Currently on step {}'.format(i))
print('Accuracy is:')
# Test the Train Model
matches = tf.equal(tf.argmax(final_output,1),tf.argmax(y_target,1))
acc = tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict={X_data:X_test,y_target:y_test}))
print('\n')
correct_prediction = tf.equal(tf.argmax(final_output,1), tf.argmax(y_target,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print("Final accuracy: ", sess.run(accuracy, feed_dict={X_data: X_test, y_target: y_test}))
我在这里的最后一步是预测手动输入值的输出。我试过这个:
prediction=tf.argmax(final_output,1)
print("Predictions")
new = [5.1,3.5,1.4,0.2]
print(prediction.eval(feed_dict={X_data: new}))
但是我收到以下错误
Cannot feed value of shape (4,) for Tensor 'Placeholder_10:0', which has shape '(?, 4)'
我真的不知道如何创建一个包含4个手动输入值的列表,这些值符合此占位符的格式
X_data = tf.placeholder(shape=[None, 4], dtype=tf.float32)
谢谢!
答案 0 :(得分:1)
只需在列表中包含 new 即可:
assert len(x.shape) == 2, "input must be 2D"
assert x.shape[1] == 16, "input must have 16 columns"
assert np.issubdtype(x.dtype, np.integer), "input must be integers"
或者喂一个numpy数组:
prediction.eval(feed_dict={X_data: [new]})