1116

1.with tf.variable_scope(name , reuse = reuse)

(1)创建variable scope

with tf.variable_scope("foo"):
    with tf.variable_scope("bar"):
        v = tf.get_variable("v", [1])
        assert v.name == "foo/bar/v:0"

(2)共享变量

with tf.variable_scope("foo"):
    v = tf.get_variable("v", [1])
with tf.variable_scope("foo", reuse=True):
    v1 = tf.get_variable("v", [1])
assert v1 == v

(3)在一个变量域中,不允许重用变量

with tf.variable_scope("foo"):
    v = tf.get_variable("v", [1])
    v1 = tf.get_variable("v", [1])
    #  Raises ValueError("... v already exists ...").

(4)当试图获取在重用模式中不存在的变量时,我们会引发异常

with tf.variable_scope("foo", reuse=True):
    v = tf.get_variable("v", [1])
    #  Raises ValueError("... v does not exists ...").

猜你喜欢

转载自www.cnblogs.com/ChenKe-cheng/p/9968207.html