【问题标题】:How to record accuracy for every iteration during sess.run in Tensorflow?如何在 Tensorflow 中记录 sess.run 期间每次迭代的准确性?
【发布时间】:2017-11-22 09:39:40
【问题描述】:

我在这里按照代码https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py 构建一个多层感知器来解决MNIST问题。

在下面的代码中,

with tf.Session() as sess:
    sess.run(init)

    # Training cycle
    for epoch in range(training_epochs):
        avg_cost = 0.
        total_batch = int(mnist.train.num_examples/batch_size)
        # Loop over all batches
        for i in range(total_batch):
            batch_x, batch_y = mnist.train.next_batch(batch_size)
            # Run optimization op (backprop) and cost op (to get loss value)
            _, c = sess.run([train_op, loss_op], feed_dict={X: batch_x,
                                                            Y: batch_y})
            # Compute average loss
            avg_cost += c / total_batch
        # Display logs per epoch step
        if epoch % display_step == 0:
            print("Epoch:", '%04d' % (epoch+1), "cost={:.9f}".format(avg_cost))
    print("Optimization Finished!")

我想记录每次迭代的准确率,仍然使用sess.run;我该怎么做?

【问题讨论】:

    标签: machine-learning tensorflow


    【解决方案1】:

    您有代码来衡量训练的准确性吗?您还需要运行该块。将它贴在Loop over all batches 块的底部,以便它在每次迭代时运行。

    如果您想要损失而不是准确性,那么只需在该位置打印avg_cost。如果您希望为每个 epoch 而不是每次迭代打印损失,然后删除模条件 if epoch % display_step == 0: 并在此之后取消缩进 print

    其中一个是否满足您的需求?

    【讨论】:

      猜你喜欢
      • 2020-02-21
      • 1970-01-01
      • 2020-04-09
      • 2018-10-20
      • 1970-01-01
      • 2017-02-28
      • 2018-03-14
      • 1970-01-01
      • 2020-11-18
      相关资源
      最近更新 更多