--- 3.1 TensorFlow calculation model calculates FIG.

  TensorFlow program can generally be divided into two stages. Calculation required to define all the figures in the first stage. The second stage is calculated to perform.
  In TensorFlow program, the system automatically maintains a default calculation map can be acquired by the current default tf.get_default_graph function calculation of FIG.
  FIG calculated using default removed, TensorFlow support the new function calculation tf.Graph generated by the FIG. Tensor calculation on different computing and will not be shared FIG. The following code illustrates how to define and use variables on different computing FIG.

tensorflow TF AS Import 

g1 = tf.Graph () 
with g1.as_default (): 
    # g1 in FIG calculation variables defined in the "v", and sets the initial value 0 
    V = tf.get_variable ( "v", = initializer of TF. zeros_initializer (Shape = [. 1])) 

g2 = tf.graph () 
with g2.as_default (): 
    # g2 in FIG calculation variables defined in the "v", and the initial value is set. 1 
    V = tf.get_variable ( "V" , = initializer of tf.ones_initializer (Shape = [. 1])) 

# g1 FIG reading calculation variable "v" values 
with tf.Session (Graph = g1) AS Sess: 
    . tf.initialize_all_variables () RUN () 
    tf.variable_scope with ( "", Reuse = True): 
        # g1 in FIG calculation, the variable "v" is the value to be 0, so that this line will output [of 0. the] 
        Print (sess.run (tf.get_variable ( "v"))) 

# reading g2 FIG calculation variable "v" values 
with tf.Session(graph = g2) as sess: 
    tf.initialize_all_variables().run()
    with tf.variable_scope("", reuse = True):
        print(sess.run(tf.get_variable("v"))
        

  

 

Guess you like

Origin www.cnblogs.com/CZT-TS/p/11234993.html