使用Tensorflow Estimator打印额外的训练指标 [英] Printing extra training metrics with Tensorflow Estimator
问题描述
在使用Estimator API时,是否可以让Tensorflow打印额外的训练指标(例如批处理准确性)?
Is there a way to let Tensorflow print extra training metrics (e.g. batch accuracy) when using the Estimator API?
一个人可以在Tensorboard中添加摘要并查看结果(请参阅另一篇文章),但是我想知道是否有一种优雅的方法来在训练时打印标量摘要值.对于训练失败,这种情况已经发生,例如:
One can add summaries and view the result in Tensorboard (see another post), but I was wondering if there is an elegant way to get the scalar summary values printed while training. This already happens for training loss, e.g.:
loss = 0.672677, step = 2901 (52.995 sec)
但是最好有一个
loss = 0.672677, accuracy = 0.54678, step = 2901 (52.995 sec)
没有太多麻烦.我知道在大多数情况下,绘制测试集准确性更为有用(我已经在使用验证监视器了),但是在这种情况下,我也对训练批处理准确性感兴趣.
without to much trouble. I am aware that most of the time it is more useful to plot test set accuracy (I am already doing this with a validation monitor), but in this case I am also interested in training batch accuracy.
推荐答案
根据我所读的内容,无法通过传递参数来对其进行更改. 您可以尝试通过创建日志记录挂钩并将其传递到估算器运行中来进行尝试.
From what I've read it is not possible to change it by passing parameter. You can try to do by creating a logging hook and passing it into to estimator run.
在model_fn
函数主体中供您估算:
In the body of model_fn
function for your estimator:
logging_hook = tf.train.LoggingTensorHook({"loss" : loss,
"accuracy" : accuracy}, every_n_iter=10)
# Rest of the function
return tf.estimator.EstimatorSpec(
...params...
training_hooks = [logging_hook])
要查看输出,还必须将日志记录详细程度设置得足够高(除非它是默认设置):
tf.logging.set_verbosity(tf.logging.INFO)
To see the output you must also set logging verbosity high enough (unless its your default):
tf.logging.set_verbosity(tf.logging.INFO)
这篇关于使用Tensorflow Estimator打印额外的训练指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!