TensorFlow;尝试打印CNN模型的丢失值时出错

时间:2017-07-26 01:04:55

标签: python tensorflow

我正在尝试修改Tensorflow.org提供的MNIST_deep.py来显示损失值。下面是代码片段:

print ("\n***** Training a prediction model... *****\n")
print ("Model: Convolutional Neural Network, Activation: ReLU + Softmax\n")

for i in range(20000):
    batch_x, batch_y = mnist.train.next_batch(50)
    sess.run(train_step, feed_dict={x: batch_x, y_: batch_y, keep_prob: 0.5})
    [_, Avg_Cost] = sess.run([train_step, cross_entropy], feed_dict = {x: batch_x, y: batch_y})

    if i % 100 == 0:
        train_accuracy = accuracy.eval(feed_dict={x: batch_x, y_: batch_y, keep_prob: 1.0})

        if (Debugged == True):
            print("Step = %05d, Training accuracy = %.2f" % (i, train_accuracy), "Average Cost = ", Avg_Cost)

        else:
            print("Step = %05d, Training accuracy = %.2f" % (i, train_accuracy))

问题在于这一行:

[_, Avg_Cost] = sess.run([train_step, cross_entropy], feed_dict = {x: batch_x, y: batch_y})

它一直告诉我形状[-1,10]具有负面尺寸。我对TensorFlow很新,我无法弄清问题在哪里。你能帮我跟踪问题的根源吗?

1 个答案:

答案 0 :(得分:0)

您的代码存在的一个问题是,您在keep_prob的通话中未传递sess.run的值。它在上面的线上传递。除非在该行上多余,否则您也需要在以下行中使用它。

如果这不能解决您的问题,请发布或链接完整版本的代码以重现此问题。