【问题标题】:About tensorboard name_scope关于张量板 name_scope
【发布时间】:2017-09-06 16:34:01
【问题描述】:

我使用 name_scope 来管理变量的命名空间,所以它可以通过 tensorboard 很好地显示出来。但我发现有些奇怪,name_scope 不会为 tf.get_variable 创建的变量添加前缀。 所以代码会报错:

with tf.name_scope(self.networkName + '/conv1'):
    self.conv1_w = tf.get_variable(shape = [8, 8, 4, 16], name = 'w', initializer=tf.contrib.layers.xavier_initializer())
    self.conv1_b = tf.get_variable(shape = [16], name = 'b', initializer=tf.contrib.layers.xavier_initializer())
    self.conv1_o = tf.nn.relu(tf.nn.conv2d(self.states, self.conv1_w, [1, 4, 4, 1], 'SAME') + self.conv1_b)

with tf.name_scope(self.networkName + '/conv2'):
    self.conv2_w = tf.get_variable(shape = [4, 4, 16, 32], name = 'w', initializer=tf.contrib.layers.xavier_initializer())
    self.conv2_b = tf.get_variable(shape = [32], name = 'b', initializer=tf.contrib.layers.xavier_initializer())
    self.conv2_o = tf.nn.relu(tf.nn.conv2d(self.conv1_o, self.conv2_w, [1, 2, 2, 1], 'SAME') + self.conv2_b)

ValueError: 变量 w 已存在,不允许使用。

我可以使用 variable_scope 代替 name_scope 吗?而tensorboard可以在variable_scope上工作吗?

【问题讨论】:

    标签: tensorflow tensorboard


    【解决方案1】:

    tf.name_scope 为范围内定义的操作定义前缀。

    tf.variable_scope 为范围内定义的操作和变量定义前缀。

    如果你想创建一个与另一个变量同名但在不同范围内的变量,你必须使用tf.variable_scope。

    tf.name_scope 用于定义自定义操作,以便很好地定义上下文。

    就我个人而言,我几乎总是使用tf.variable_scope。

    此外,是的,tf.variable_scope 在 tensorboard 中创建漂亮的图形,与 tf.named_scope 完全一样

    【讨论】:

      猜你喜欢
      • 2020-04-29
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      相关资源
      最近更新 更多