0
我一直在调查tensorflow docs一些方法来检索变量使用绝对名称,而不是相对名称现有范围绝对范围访问变量
喜欢的东西get_variable_absolute
,将收到的VAR的绝对路径(即:h1/Weights
而不是Weights
在h1
变量范围内)
这个问题的动机是极端的沮丧与this problem。
我一直在调查tensorflow docs一些方法来检索变量使用绝对名称,而不是相对名称现有范围绝对范围访问变量
喜欢的东西get_variable_absolute
,将收到的VAR的绝对路径(即:h1/Weights
而不是Weights
在h1
变量范围内)
这个问题的动机是极端的沮丧与this problem。
我从TensorFlow深入阅读tutorial on Sharing Variables后发现了答案。
假设:
为此,您需要保存使用tf.variable_scope('h1')
创建的作用域对象,以便在作用域'foo'中使用它。
一些代码将更加雄辩:
with tf.variable_scope('h1') as h1_scope: # we save the scope object in h1_scope
w = tf.get_variable('Weights', [])
with tf.variable_scope('foo'):
with tf.variable_scope(h1_scope, reuse=True): # get h1_scope back
w2 = tf.get_variable('Weights')
assert w == w2
结论:当你通过其Python对象的范围,而不仅仅是它的名字,就可以摆脱目前的范围。