tf.valuable_scope()函式/類用法
阿新 • • 發佈:2018-12-05
官網的解釋和例子實在是wast time,不用去看它了。
import tensorflow as tf a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1)) with tf.variable_scope('V1'): a2 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2') with tf.variable_scope('V2'): a3 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(80)) print (a1.name) print (a2.name) print (a3.name) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) print(sess.run(a1)) print(sess.run(a2)) print(sess.run(a3))
輸出結果可以看出,V1是範圍,變數名a2在V1範圍。變數名a1在V2範圍。後面的輸出value可以看出,此函式主要是用於name管理。然而此a1非彼a1,一般我們用的是tensor.Variable。
type(a1)
Out[2]: tensorflow.python.ops.variables.Variable
type(a3)
Out[3]: tensorflow.python.ops.variables.Variable