通过名称作用域组织数据流图

#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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容