Tensorflow - 使用 tf.summary 和 1.2 Estimator API [英] Tensorflow - Using tf.summary with 1.2 Estimator API

查看:35
本文介绍了Tensorflow - 使用 tf.summary 和 1.2 Estimator API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向使用新 tf.estimator API 的模型添加一些 TensorBoard 日志记录.

I'm trying to add some TensorBoard logging to a model which uses the new tf.estimator API.

我有一个像这样设置的钩子:

I have a hook set up like so:

summary_hook = tf.train.SummarySaverHook(
    save_secs=2,
    output_dir=MODEL_DIR,
    summary_op=tf.summary.merge_all())

# ...

classifier.train(
    input_fn,
    steps=1000,
    hooks=[summary_hook])

在我的 model_fn 中,我也在创建一个 summary -

In my model_fn, I am also creating a summary -

def model_fn(features, labels, mode):
    # ... model stuff, calculate the value of loss
    tf.summary.scalar("loss", loss)
    # ...

但是,当我运行此代码时,我从 summary_hook 收到以下错误:必须提供 scaffold 或 summary_op 中的一个. 这可能是因为 tf.summary.merge_all() 没有找到任何摘要并且返回 None,尽管我在 model_fn 中声明了 tf.summary.scalar.

However, when I run this code, I get the following error from the summary_hook: Exactly one of scaffold or summary_op must be provided. This is probably because tf.summary.merge_all() is not finding any summaries and is returning None, despite the tf.summary.scalar I declared in the model_fn.

知道为什么这行不通吗?

Any ideas why this wouldn't be working?

推荐答案

对于以后有这个问题的人来说,所选的解决方案对我不起作用(请参阅我在所选解决方案中的评论).

Just for whoever have this question in the future, the selected solution doesn't work for me (see my comments in the selected solution).

实际上,使用 TF 1.2 Estimator API,不需要summary_hook.我在model_fn 中只有tf.summary.scalar("loss", loss),并且在没有summary_hook 的情况下运行代码.损失被记录并显示在张量板中.我不确定在此和类似问题之后是否更改了 TF API.

Actually, with TF 1.2 Estimator API, one doesn't need to have summary_hook. I just have tf.summary.scalar("loss", loss) in the model_fn, and run the code without summary_hook. The loss is recorded and shown in the tensorboard. I'm not sure if TF API was changed after this and similar questions.

这篇关于Tensorflow - 使用 tf.summary 和 1.2 Estimator API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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