2016-07-20 58 views
1
with tf.variable_scope('aa') as sa: 
    with tf.variable_scope('bb'): 
     x = tf.get_variable(
      'biases', (2,), 
      initializer=tf.constant_initializer() 
     ) 
     y1 = tf.identity(x, name='bb') 
with tf.variable_scope(sa): 
    with tf.variable_scope('cc'): 
     x = tf.get_variable(
      'biases', (2,), 
      initializer=tf.constant_initializer() 
     ) 
     y2 = tf.identity(x, name='cc') 

我輸入了兩次tf.variable_scope('aa'),並生成了兩個張量y1,y2如何強制tf.variable_scope重用name_scope?

但是,y2.name == 'aa_1/cc/cc:0'。 (y1.name == 'aa/bb/bb:0'

是否可以改爲y2.name == 'aa/cc/cc:0'

回答

2

現在有點晚了,但試着在名稱範圍的末尾添加一個/,以明確指示您要重用範圍。否則,如您注意到的那樣,它會添加一個_1。我與name_scope有類似的問題,但我認爲該解決方案也適用於variable_scope

with tf.variable_scope('aa/'): 
    ... # Some initialisation 
with tf.variable_scope('aa/'): 
    ... # Reuse the name scope