# tf.get_variable和tf.Variable的区别:
- tf.Variable()遇到同名的变量时会产生一个新的,并不会共存。
tf.get_variable()通常和tf.variable_scope()一起使用,可用来共享变量。tf.get_variable(name, shape, initializer): 通过所给的名字创建或是返回一个变量,tf.variable_scope(): 通过 tf.get_variable()为变量名指定命名空间。
# tf.name_scope只能限制op,不能限制变量的命名。例如:
with tf.Variable_scope('scope'):
with tf.name_scope('bar'):
v = tf.get_variable('v',[1])
x = 1.0 + v
print(v.name)
print(x.op.name)
上面一段代码的输出为:
scope/v:0
scope/bar/add