简体   繁体   English

Tensorflow 形状不匹配

[英]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.

相关问题 Python Tensorflow 形状不匹配(WaveNet) - Python Tensorflow Shape Mismatch (WaveNet) 形状与 Tensorflow 数据集和网络不匹配 - Shape mismatch with Tensorflow Dataset and Network Tensorflow:一维数据的形状不匹配问题 - Tensorflow : Shape mismatch issue with one dimensional data Tensorflow2 关于形状不匹配的警告,仍在训练 - Tensorflow2 Warning on Shape Mismatch, Still Training Tensorflow 2:序列化和解码时形状不匹配 - Tensorflow 2: shape mismatch when serialize and decode it back 从 SavedModel 格式恢复的模型输入形状的 Tensorflow 不匹配 - Tensorflow mismatch of input shape from model restored from SavedModel format 使用 yolo4.cfg 进行 tensorflow 2.2 训练中的形状不匹配问题 - Shape mismatch problem in tensorflow 2.2 training using yolo4.cfg Tensorflow/Keras:训练数据和预测数据中的 Output 形状不匹配 - Tensorflow/Keras: Output shape mismatch in training data and predicted data TensorFlow 2.0 SparseCategoricalCrossentropy valueError: Shape mismatch: 标签的形状应该等于 logits 的形状,除了最后一个 - TensorFlow 2.0 SparseCategoricalCrossentropy valueError: Shape mismatch: The shape of labels should equal the shape of logits except for the last Tensorflow fit ValueError: Shape mismatch: the shape of labels (received (16640,)) 应该等于 logits 的形状,除了最后一个维度 - Tensorflow fit ValueError: Shape mismatch: The shape of labels (received (16640,)) should equal the shape of logits except for the last dimension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM