1. 程式人生 > >tensorflow-新的計算圖

tensorflow-新的計算圖

生成新的計算圖,並完成常量初始化,在新的計算 圖中完成加法計算

import tensorflow as tf

g1=tf.Graph()

with g1.as_default():

   value=[1.,2.,3.,4.,5.,6.]

   init = tf.constant_initializer(value)

   x=tf.get_variable("x",initializer=init,shape=[2,3])

   y=tf.get_variable("y",shape=[2,3],initializer=tf.ones_initializer())

   result=tf.add(x,y,name="myadd")

with tf.Session(graph=g1) as sess:

   tf.global_variables_initializer().run()

   with tf.variable_scope("",reuse=True):

       print(sess.run(tf.get_variable("x")))

       print(sess.run(tf.get_variable("y")))

   print(sess.run(result))