0

Hej,

in the final step of my multi-class neural network for the IRIS data set, I am executing the following code:

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

My last step here would be to predict the output of manually entered values. I tried this:

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

but I get the following error

Cannot feed value of shape (4,) for Tensor 'Placeholder_10:0', which has shape '(?, 4)'

I don't really know how to create a list with 4 manual entered values that would fit into the format of this placeholder

X_data = tf.placeholder(shape=[None, 4], dtype=tf.float32)

Thank you!

1 Answers1

1

Simply wrap new in a list should work:

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

Or feed a numpy array:

prediction.eval(feed_dict={X_data: np.reshape(new, (-1,4))})
Psidom
  • 209,562
  • 33
  • 339
  • 356