0

HeJ小鼠,無法爲張量「Placeholder_10:0」喂形狀的值(4),其具有形狀「(?,4)」

在我的多類神經網絡用於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) 

謝謝!

回答

1

列表中的簡單包裝應該工作:

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

或飼料一numpy的數組:

prediction.eval(feed_dict={X_data: np.reshape(new, (-1,4))}) 
+1

完美的,就像一個魅力! – Schnurrberto

相關問題