使用 Tensorflow Estimator 打印额外的训练指标 [英] Printing extra training metrics with Tensorflow Estimator

查看:83
本文介绍了使用 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.

推荐答案

据我所知,通过传递参数是不可能改变它的.您可以尝试通过创建日志挂钩并将其传递给 estimator run 来实现.

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆