编译并拟合占位符,导致ValueError

时间:2019-05-16 12:31:15

标签: python-3.x tensorflow conv-neural-network

已要求我为给定的数据集生成CNN输出。 我跑步时收到此错误 ValueError: Cannot feed value of shape (16, 10) for Tensor 'Placeholder_4:0', which has shape '(?, 60, 11, 1)'

我正在本地主机的jupyter笔记本中工作。我正在使用英特尔python(idp)。

数据集包含在下面

Att1    Att2    Att3    Att4    Att5    Att6    Att7    Att8    Att9    Att10   Att11
1   0   1   0.9471  C   0   S   0.8561  0.002   0.004   1.8091
1   0   1   0.992   C   0   S   0.8648  0.002   0.003   1.861
1   0   1   1.0722  C   0   S   2.009   0.002   0.003   3.0876
1   0   1   0.994   C   0   S   0.8754  0.002   0.003   1.8744
1   0   1   1.0121  C   0   S   0.9275  0.002   0.003   1.9447
1   0   1   0.9825  C   0   S   0.9579  0.002   0.003   1.9455
1   0   1   0.7372  C   0   S   0.8699  0.002   0.003   1.6122
1   0   1   0.9533  C   0   S   0.8377  0.002   0.004   1.797

共有11个属性和60行数据。我只展示了其中的一小部分

最后一部分,即tf.Session()部分正在产生此错误。仅粘贴必要的代码段。有关完整代码,请让我知道

# from tensorflow.examples.tutorials.mnist import input_data
# data = input_data.read_data_sets('data/fashion',one_hot=True)
X = dfg[['Att1','Att2','Att3','Att4',
         'Att5_C', 
         'Att6',
         'Att7_S', 
         'Att8','Att9','Att10']]

Y = dfg[['Att11']]
train_X, test_X,train_y,test_y = train_test_split(X,Y,train_size=0.88,random_state=5)
pred = conv_net(x, weights, biases)

cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))

optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)

#Here you check whether the index of the maximum value of the predicted image is equal to the actual labelled image. and 
# both will be a column vector.
correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))

#calculate accuracy across all the given images and average them out. 
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init) 
    train_loss = []
    test_loss = []
    train_accuracy = []
    test_accuracy = []
    summary_writer = tf.summary.FileWriter('./Output', sess.graph)
    for i in range(training_iters):
        for batch in range(len(train_X)//batch_size):
            batch_x = train_X[batch*batch_size:min((batch+1)*batch_size,len(train_X))]
            batch_y = train_y[batch*batch_size:min((batch+1)*batch_size,len(train_y))]    
            # Run optimization op (backprop).
                # Calculate batch loss and accuracy
            opt = sess.run(optimizer, feed_dict={x: batch_x,
                                                              y: batch_y})
            loss, acc = sess.run([cost, accuracy], feed_dict={x: batch_x,
                                                              y: batch_y})
        print("Iter " + str(i) + ", Loss= " + \
                      "{:.6f}".format(loss) + ", Training Accuracy= " + \
                      "{:.5f}".format(acc))
        print("Optimization Finished!")

        # Calculate accuracy for all 10000 mnist test images
        test_acc,valid_loss = sess.run([accuracy,cost], feed_dict={x: test_X,y : test_y})
        train_loss.append(loss)
        test_loss.append(valid_loss)
        train_accuracy.append(acc)
        test_accuracy.append(test_acc)
        print("Testing Accuracy:","{:.5f}".format(test_acc))
    summary_writer.close()

我应该制作一张图表,显示各种学习率和输入大小变化时学习曲线的增长。

0 个答案:

没有答案