在TensorFlow中显示图形图像? [英] Display image of graph in TensorFlow?

查看:300
本文介绍了在TensorFlow中显示图形图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的脚本来计算从1,2,5的黄金比例。有没有一种方法可以通过张量流(可能借助 matplotlib networkx )实际产生视觉效果图结构?张量流图非常类似于因子图,所以我想知道:

通过张量流生成图结构的图像



在下面的这个例子中,它是 C_1,C_2,C_3 作为单个节点,然后是 C_1 会有 tf.sqrt 操作,然后是将它们放在一起的操作。也许图结构(节点,边)可以被导入到 networkx 中?我发现张量对象有一个属性,但我还没有发现如何实际使用它来进行成像目的。


$ b $ pre $ #!/ usr / bin / python

导入tensorflow为tf
C_1 = tf.constant(5.0)
C_2 = tf.constant(1.0)
C_3 = tf.constant(2.0)

golden_ratio =(tf.sqrt(C_1)+ C_2) / C_3
$ b $ sess = tf.Session()
print sess.run(golden_ratio)#1.61803
sess.close()


解决方案

您可以使用 Tensorboard 。您需要编辑代码才能输出图形,然后可以启动张量板并查看它。尤其请参阅 TensorBoard:Graph Visualization 。你创建一个 SummaryWriter ,并在其中包含 sess.graph_def 。图形def将输出到日志目录。


I wrote a simple script to calculate the golden ratio from 1,2,5. Is there a way to actually produce a visual through tensorflow (possibly with the aid of matplotlib or networkx) of the actual graph structure? The doc of tensorflow is pretty similar to a factor graph so I was wondering:

How can an image of the graph structure be generated through tensorflow?

In this example below, it would be C_1, C_2, C_3 as individual nodes, and then C_1 would have the tf.sqrt operation followed by the operation that brings them together. Maybe the graph structure (nodes,edges) can be imported into networkx? I see that the tensor objects have a graph attribute but I haven't found out how to actually use this for imaging purposes.

#!/usr/bin/python

import tensorflow as tf
C_1 = tf.constant(5.0)
C_2 = tf.constant(1.0)
C_3 = tf.constant(2.0)

golden_ratio = (tf.sqrt(C_1) + C_2)/C_3

sess = tf.Session()
print sess.run(golden_ratio) #1.61803
sess.close()

解决方案

You can get an image of the graph using Tensorboard. You need to edit your code to output the graph, and then you can launch tensorboard and see it. See, in particular, TensorBoard: Graph Visualization. You create a SummaryWriter and include the sess.graph_def in it. The graph def will be output to the log directory.

这篇关于在TensorFlow中显示图形图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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