Display image of graph in TensorFlow?

让人想犯罪 __ 提交于 2019-11-30 04:47:43
dga

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.

Salvador Dali

This is exactly what tensorboard was created for. You need to slightly modify your code to store the information about your graph.

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

with tf.Session() as sess:
    writer = tf.summary.FileWriter('logs', sess.graph)
    print sess.run(golden_ratio)
    writer.close()

This will create a logs folder with event files in your working directory. After this you should run tensorboard from your command line tensorboard --logdir="logs" and navigate to the url it gives you (http://127.0.0.1:6006). In your browser go to GRAPHS tab and enjoy your graph.

You will use TB a lot if you are going to do anything with TF. So it makes sense to learn about it more from official tutorials and from this video.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!