我想寫一個代碼來創建一個神經網絡。它應該從特定的csv
文件讀取數據,該文件包含13
與每個輸入不同的特徵。這裏是我的代碼片段:形狀不匹配Tensorflow
n_inputs = 13
X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X")
y = tf.placeholder(tf.int64, shape=None, name="y")
def data_processor(n):
id = pd.read_csv('./subset_numerical/'+patient_id[n])
id_input = np.array(id['VALUE'].tolist())
for s in sepsis_pat:
if str(s) == str(patient_id[n].split('.')[0]):
a = 1
try:
if a == 1:
a = 0
return [id_input, np.array([1, 0])]
except:
return [id_input, np.array([0, 1])]
我tf.Session()
部分看起來是這樣的:
with tf.Session() as sess:
init.run()
for epoch in range(n_epochs):
a = 0
for iteration in range(300 // batch_size):
X_batch, y_batch = data_processor(iteration)
print((X_batch))
sess.run(training_op, feed_dict={X: X_batch, y: y_batch})
acc_train = accuracy.eval(feed_dict={X: X_batch, y: y_batch})
print(epoch, "Train accuracy:", acc_train)
save_path = saver.save(sess, "./my_model_final.ckpt")
的問題是:執行後,它顯示了以下錯誤:
Can not feed value of shape (13,) for tensor 'X:0', which has shape (?,13)
什麼是錯的用它?
嘗試運行'X_batch,y_batch = data_processor(1)';結果'X_batch'的形狀是什麼? – desertnaut