[英]Mismatch in shape Tensorflow
I am trying to write a code to create a neural network.我正在尝试编写代码来创建神经网络。 It is supposed to read data from a particular
csv
file that contains 13
distinctive features for each individual inputs.它应该从包含每个单独输入的
13
不同特征的特定csv
文件中读取数据。 Here is my code snippet:这是我的代码片段:
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])]
My tf.Session()
part looks like this:我的
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")
The problem is : after execution, it shows the following error:问题是:执行后,显示以下错误:
Can not feed value of shape (13,) for tensor 'X:0', which has shape (?,13)
What is wrong with it?它有什么问题?
Your X
placeholder expects an input with shape=(None, n_inputs)
and X_batch
has the shape of n_inputs
so the shapes don't match.您的
X
占位符预计与输入shape=(None, n_inputs)
和X_batch
具有的形状n_inputs
所以形状不匹配。
You can solve the problem by putting n_inputs
into a list making its shape (1, n_inputs):您可以通过将
n_inputs
放入一个列表来解决这个问题,使其形状为 (1, n_inputs):
sess.run(training_op, feed_dict={X: [X_batch], y: y_batch})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.