0

嘿嘿,

在 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)

谢谢!

4

1 回答 1

1

只需将新包装在列表中即可:

prediction.eval(feed_dict={X_data: [new]})

或者提供一个 numpy 数组:

prediction.eval(feed_dict={X_data: np.reshape(new, (-1,4))})
于 2017-11-11T03:32:13.333 回答