tensorflow之tf.varable_scope()

tf.variable_scope()

作用:对给定变量添加变量空间名,不同空间中可以存在相同名称的变量;但同一空间中不能出现两个相同的变量
参数:reuse = True,表示该变量在空间之内共享,即可重复利用

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

猜你喜欢

转载自blog.csdn.net/yangwangnndd/article/details/89920528