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浏览器,输入得的的网址即可看到 我们生成的流程图了:

TensorFlow 构建流程图

相关文章:

  • 2021-07-06
  • 2021-11-12
  • 2022-01-03
  • 2022-12-23
  • 2021-11-17
  • 2021-12-26
  • 2021-10-22
  • 2021-04-27
猜你喜欢
  • 2021-09-30
  • 2022-02-02
  • 1970-01-01
  • 2021-12-13
  • 2022-01-05
  • 2021-06-12
  • 2021-12-18
相关资源
相似解决方案