在 Tensorflow 中,是否可以将一些摘要附加到已合并的 summary_op 中? [英] In Tensorflow, is it possible to append some summaries to already-merged summary_op?

查看:23
本文介绍了在 Tensorflow 中,是否可以将一些摘要附加到已合并的 summary_op 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,一些内置函数返回 train_opsummary_op 其中 summary_optf.summary.merge(summaries, name='summary_op'),我无法触及该功能.

Let's say, some built-in function returns train_op and summary_op where summary_op is defined by tf.summary.merge(summaries, name='summary_op'), and I cannot touch the function.

另外,假设我将使用内置的 slim.learning.train,它以 train_opsummary_op 作为输入参数.

Also, let's say, I am going to use the built-in slim.learning.train which takes train_op and summary_op as input arguments.

# -- typical
train_op, summary_op = model_fn(image)
slim.learning.train(train_op, summary_op=summary_op)

# -- my question
train_op, summary_op = model_fn(image)
some_other_summary_list = some_another_function()
summary_op_ = ...  # is it possible to append some_other_summary_list to summary_op?
slim.learning.train(train_op, summary_op=summary_op_)

如何将已合并的summary_op 中的摘要与新收集的摘要some_other_summary_list 合并?

How I can combine summaries in already-merged summary_op and newly-collected summaries some_other_summary_list?

-- 如果我这样做 tf.merge_all(tf.GraphKeys.SUMMARIES) 实际上会有太多的摘要,因为在 model_fn() 中只收集有用和必要的总结.

-- If I do tf.merge_all(tf.GraphKeys.SUMMARIES) actually there will be too many summaries since, in model_fn() collect only useful and necessary summaries.

-- 我可以考虑定义单独的 summary_op2 并将 train_step_fn 定义为:

-- I can think of defining separate summary_op2 and define train_step_fn as in:

from tensorflow.contrib.slim.python.slim.learning import train_step
def train_step_fn(...):
    ... = train_step(...)
    if iteration % 100 == 0: 
        summaries = session.run(summary_op2)
        summary_writer.add_summary(summaries, iteration)
slim.learning.train(train_op, summary_op=summary_op, train_step_fn=train_step_fn)

然而,如果我能以某种方式简单地将新摘要附加到 summary_op,这似乎太过分了.可能吗?

However, this seems too much if I can simply somehow append new summaries to summary_op. Is it possible?

推荐答案

如果summary_op 和新收集的summaries some_other_summary_list"都是由 tf.summary.merge,你可以简单地通过 tf.summary.merge([summary_op, summaries some_other_summary_list]) 再次合并它们,如下代码所示:

If both "summary_op and newly-collected summaries some_other_summary_list" are created by tf.summary.merge, you can simply merge them again by tf.summary.merge([summary_op, summaries some_other_summary_list]), as demonstrated by this code:

import tensorflow as tf

a = tf.summary.scalar('a', tf.constant(0))
b = tf.summary.scalar('b', tf.constant(1))
c = tf.summary.scalar('c', tf.constant(2))
d = tf.summary.scalar('d', tf.constant(3))

ab = tf.summary.merge([a, b])
cd = tf.summary.merge([c, d])
abcd = tf.summary.merge([ab, cd])

with tf.Session() as sess:
    writer = tf.summary.FileWriter('.', sess.graph)
    summary = sess.run(abcd)
    writer.add_summary(summary)

这篇关于在 Tensorflow 中,是否可以将一些摘要附加到已合并的 summary_op 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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