我正在尝试编写代码来创建神经网络。它应该从特定csv
文件中读取数据,该文件包含每个输入的13
个独特功能。这是我的代码片段:
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)
它出了什么问题?
答案 0 :(得分:1)
您的X
占位符预计shape=(None, n_inputs)
和X_batch
的输入形状为n_inputs
,因此形状不匹配。
您可以通过将n_inputs
放入形成其形状的列表(1,n_inputs)来解决问题:
sess.run(training_op, feed_dict={X: [X_batch], y: y_batch})