热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Tensorflow——使用tf。总结1.2估计器API-Tensorflow-Usingtf.summarywith1.2EstimatorAPI

ImtryingtoaddsomeTensorBoardloggingtoamodelwhichusesthenewtf.estimatorAPI.我正在尝试向使用

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

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

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])

In my model_fn, I am also creating a summary -

在我的model_fn中,我还创建了一个摘要。

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

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.

但是,当我运行这段代码时,我从summary hook中得到了以下错误:必须提供一个scaffold或summary_op。这可能是因为tf.summary.merge_all()没有找到任何摘要,也没有返回任何摘要,尽管有tf.summary。我在model_fn中声明的标量。

Any ideas why this wouldn't be working?

你知道为什么这行不通吗?

3 个解决方案

#1


4  

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

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

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.

实际上,使用TF 1.2 Estimator API,不需要使用summary_hook。我只有tf.summary。在model_fn中,标量(“丢失”,丢失),并运行代码,而不使用摘要挂钩。损失被记录并显示在租船板上。我不确定TF API是否在这个问题和类似的问题之后被修改。

#2


5  

Use tf.train.Scaffold() and pass tf.merge_all as following

使用tf.train. scaffold()并通过tf。merge_all如下

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

#3


0  

with Tensorflow ver-r1.3

与Tensorflow ver-r1.3

Add your summary ops in your estimator model_fn

在估计器model_fn中添加汇总操作

example :

例子:

tf.summary.histogram(tensorOp.name, tensorOp)

If you feel writing summaries may consume time and space, you can control the writing frequency of summaries, in your Estimator run_config

如果您认为编写摘要可能会消耗时间和空间,那么可以在估计器run_config中控制编写摘要的频率

run_cOnfig= tf.contrib.learn.RunConfig()
run_cOnfig= run_config.replace(model_dir=FLAGS.model_dir)
run_cOnfig= run_config.replace(save_summary_steps=150)

Note: this will affect the overall summary writer frequency for TensorBoard logging, of your estimator (tf.estimator.Estimator)

注意:这将影响您的估计器(tf.estimator.Estimator)的TensorBoard日志记录的总编写者频率。


推荐阅读
author-avatar
穿脚蹼的鱼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有