TensorFlow 構建流程圖

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瀏覽器,輸入得的的網址即可看到 我們生成的流程圖了:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章