Printing the loss during TensorFlow training

后端 未结 2 996
無奈伤痛
無奈伤痛 2020-12-23 16:49

I am looking at the TensorFlow \"MNIST For ML Beginners\" tutorial, and I want to print out the training loss after every training step.

My training loop currently l

2条回答
  •  萌比男神i
    2020-12-23 17:27

    Instead of just running the training_step, run also the cross_entropy node so that its value is returned to you. Remember that:

    var_as_a_python_value = sess.run(tensorflow_variable)
    

    will give you what you want, so you can do this:

    [_, cross_entropy_py] = sess.run([train_step, cross_entropy],
                                     feed_dict={x: batch_xs, y_: batch_ys})
    

    to both run the training and pull out the value of the cross entropy as it was computed during the iteration. Note that I turned both the arguments to sess.run and the return values into a list so that both happen.

提交回复
热议问题