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
