我知道我可以使用'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' !!!
谢谢!