tensorflow摘要 - 编写多个图形

时间:2017-07-02 13:18:39

标签: tensorflow tensorboard

我有使用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()

在张量板上,我明白了:

enter image description here

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

1 个答案:

答案 0 :(得分:2)

您对tf.summary.FileWriter的第二次电话会覆盖您的第一个档案。

如果你写一个不同的文件,通过在打开第二个之前关闭第一个作者,会发生什么?

  

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

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

  

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

修改

请注意,张量流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的原因之一。