通過名稱作用域組織數(shù)據(jù)流圖

#coding=utf-8
import tensorflow as tf

with tf.name_scope("Scope_A"):
    a = tf.add(1, 2, name = "A_add")
    b = tf.mul(a, 3, name = "A_mul")

with tf.name_scope("Scope_B"):
    c = tf.add(4, 5, name = "B_add")
    d = tf.mul(c, 6, name = "B_mul")

e = tf.add(b, d, name = "output")

writer = tf.train.SummaryWriter('./name_scope_1', graph = tf.get_default_graph())
writer.close()

tensorboard --logdir='./name_scope_1'
image.png
#coding=utf-8
import tensorflow as tf

graph = tf.Graph()

with graph.as_default():
    in_1 = tf.placeholder(tf.float32, shape = [], name = "input_a")
    in_2 = tf.placeholder(tf.float32, shape = [], name = "input_b")
    const = tf.constant(3, dtype = tf.float32, name = "static_value")

    with tf.name_scope("Transformation"):
        with tf.name_scope("A"):
            A_mul = tf.mul(in_1, const)
            A_out = tf.sub(A_mul, in_1)

        with tf.name_scope("B"):
            B_mul = tf.mul(in_2, const)
            B_out = tf.sub(B_mul, in_2)

        with tf.name_scope("C"):
            C_div = tf.div(A_out, B_out)
            C_out = tf.add(C_div, const)

        with tf.name_scope("D"):
            D_div = tf.div(B_out, A_out)
            D_out = tf.add(D_div, const)
            out = tf.maximum(C_out, D_out)

        writer = tf.train.SummaryWriter('./name_scope_2', graph = graph)
        writer.close()
image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容