hw_scope



In [1]:
import tensorflow as tf
with tf.name_scope("homework1"):
    with tf.name_scope("scope_1"):
        a = 7
        c = tf.pow(a,2)
       
    with tf.name_scope("scope_2"):
        b = 4
        d = tf.pow(b,2)
        
    with tf.name_scope("scope_3"):
        f = tf.multiply(tf.multiply(2,a),b)
    with tf.name_scope("scope_4"):
        e = tf.add(c,d)
    with tf.name_scope("scope_5"):
        g = tf.subtract(e,f)       
       
        
        
with tf.Session() as sess:
    writer = tf.summary.FileWriter("/tmp/tboard/output_scope", sess.graph)
    print(sess.run(g))
    writer.close()


9

In [4]:
import tensorflow as tf
with tf.name_scope("homework2"):
        with tf.name_scope("a2"):

            a = 6
            d = tf.pow(a,2) 
        with tf.name_scope("b2"):
            b = 2
            e = tf.pow(b,2) 
        with tf.name_scope("c2"):
            c = 3
            f = tf.pow(c,2)
        with tf.name_scope("Add_sqrabc"):
            g = tf.add(tf.add(d,e),f)
        with tf.name_scope("2ab"):
            h = tf.multiply(tf.multiply(2,a),b)
        with tf.name_scope("2bc"):
            i = tf.multiply(tf.multiply(2,c),b)
        with tf.name_scope("2ac"):
            j = tf.multiply(tf.multiply(2,a),c)
        with tf.name_scope("Add_sqrabc_2ab"):
            k = tf.add(g,h)
        with tf.name_scope("Add_2bc_2ca"):
            l = tf.add(i,j)
        with tf.name_scope("result"):
            m = tf.subtract(k,l)

with tf.Session() as sess:
    writer = tf.summary.FileWriter("/tmp/tboard/output2_scope", sess.graph)
    print(sess.run(m))
    writer.close()


25