tf.Graph() 表示实例化了一个类,一个用于 tensorflow 计算和表示用的数据流图,通俗来讲就是:在代码中添加的操作(画中的结点)和数据(画中的线条)都是画在纸上的“画”,而图就是呈现这些画的纸,你可以利用很多线程生成很多张图,但是默认图就只有一张。
例如有如下代码:
import tensorflow as tf g = tf.Graph() ## add nodes to the graph with g.as_default(): a = tf.constant(1, name='a') b = tf.constant(2, name='b') c = tf.constant(3, name='c') z = 2 * (a - b) + c ## launch the graph with tf.Session(graph=g) as sess: writer = tf.summary.FileWriter("E://PycharmProjects//Graph", g) print('2*(a-b)+c => ', sess.run(z))
打开cmd命令行,输入tensorboard --logdir=E:\PycharmProjects\Graph
回车后,打开google浏览器,输入得的的网址即可看到 我们生成的流程图了: