2017-07-02 40 views
0

我有使用tensorflow一个下面的代码:tensorflow总结 - 写多个图形

g1 = tf.Graph() 
g2 = tf.Graph() 

with g1.as_default(): 
    a = tf.constant(3) 
    b = tf.constant(4) 
    c = tf.add(a, b) 

with g2.as_default(): 
    x = tf.constant(5) 
    y = tf.constant(2) 
    z = tf.multiply(x, y) 

writer = tf.summary.FileWriter("./graphs", g1) 
writer = tf.summary.FileWriter("./graphs", g2) 
writer.close() 

而且在tensorboard,我得到这个:

enter image description here

但它缺少第一个图表。有没有办法绘制两个图?

回答

2

您第二次致电tf.summary.FileWriter会覆盖您的第一个文件。

如果您通过在打开第二个作者之前关闭第一个作者来写入其他文件,会发生什么?

警告tensorflow:每次运行发现多个图事件,或者有一个包含graph_def的元图,以及一个或多个图事件。用最新的事件覆盖图形。

所以看起来张量板还没有准备好处理多个图。我们应该担心吗?引用Yaroslav Bulatov

在一个过程中使用多个图通常是一个可怕的错误。

EDIT

。注意,tensorflow Graph可以承载几个,非连接的组件,有效地代表几个不同的曲线图。例如,

import tensorflow as tf 

g = tf.Graph() 
with g.as_default(): 
    a = tf.constant(3) 
    b = tf.constant(4) 
    c = tf.add(a, b) 

    x = tf.constant(5) 
    y = tf.constant(2) 
    z = tf.multiply(x, y) 

writer = tf.summary.FileWriter("./graphs", g) 
writer.close() 

结果如下

enter image description here

这就是为什么使用几个Graph一般不需要S的原因之一。