TensorFlow函数,三tf.variable_scope( 和 tf.name_scope(

tf.name_scope()

此函数作用是共享变量。在一个作用域scope内共享一些变量,简单来说,就是给变量名前面加个变量空间名,只限于tf.Variable()的变量

tf.variable_scope()

和tf.name_scope()作用一样,不过包括tf.get_variable()的变量和tf.Variable()的变量

在同一个程序中多次调用,在第一次调用之后需要将reuse参数设置为True

1 with tf.variable_scope("one"):
2     a = tf.get_variable("v", [1]) #a.name == "one/v:0"
3 with tf.variable_scope("one"):
4     b = tf.get_variable("v", [1]) #创建两个名字一样的变量会报错 ValueError: Variable one/v already exists 
5 with tf.variable_scope("one", reuse = True): #注意reuse的作用。
6     c = tf.get_variable("v", [1]) #c.name == "one/v:0" 成功共享,因为设置了reuse