整个范围路径是否需要匹配TensorFlow中的变量重用?

时间:2016-09-19 14:40:20

标签: python tensorflow

变量Test是否在这两种情况下共享?

with tf.name_scope("ns1"):
  with tf.variable_scope("vs1"):
    var = tf.get_variable("Test", [1,2,3])

with tf.name_scope("ns2"):
  with tf.variable_scope("vs1", reuse=True):
    var = tf.get_variable("Test", [1,2,3])

with tf.name_scope("ns1"):
  with tf.variable_scope("vs1"):
    var = tf.get_variable("Test", [1,2,3])

with tf.variable_scope("vs1", reuse=True):
  var = tf.get_variable("Test", [1,2,3])

1 个答案:

答案 0 :(得分:2)

是的,变量是共享的。通常,name_scope 影响变量名称,只有variable_scope会这样做(但是,是的,variable_scopes的整个前缀必须匹配)。我认为尝试完全不使用name_scope是合理的,当与variable_scope混合使用时可能会造成混淆。另请注意,您设置了reuse = True - 如果变量未共享,则会出现错误。这就是为什么它存在,所以你可以确定它是共享的。