张量流增量嵌套variable_scope

时间:2018-11-21 12:48:48

标签: python tensorflow scope

我知道我可以使用'default_name'参数来增加variable_scope:

import tensorflow as tf
tf.variable_scope("A") # This is scope "A"
tf.variable_scope(None, "A") # incremented scope "A_1"

但是,当重新输入外部上下文时,这不再起作用

reuse= tf.AUTO_REUSE
with tf.variable_scope("A", reuse=reuse):
    with tf.variable_scope("B", reuse=tf.AUTO_REUSE):
        print tf.get_variable("x", (), tf.float32) # 'A/B/x:0'        
    with tf.variable_scope(None, "B"): # Increment B, as expected
        print tf.get_variable("x", (), tf.float32) # 'A/B_1/x:0'
# Re-enter A and try to increment B
with tf.variable_scope("A", reuse=reuse):    
    with tf.variable_scope(None, "B"): # Does not increment B !!!
        print tf.get_variable("x", (), tf.float32) # 'A/B/x:0' !!!
  • 重新输入“ A”后,是否可以增加“ B”?
  • 重新输入的上下文与初始上下文A共享其变量,但不增加其内部上下文的方式。我觉得这很令人困惑,并对基本原理感到好奇。

谢谢!

0 个答案:

没有答案