关于tensorboard name_scope

Gau*_*uss 0 tensorflow tensorboard

我使用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)
Run Code Online (Sandbox Code Playgroud)

ValueError:变量w已存在,不允许.

我可以使用variable_scope而不是name_scope吗?tensorboard可以在variable_scope上工作吗?

nes*_*uno 7

tf.name_scope为作用域内定义的操作定义前缀.

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

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

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

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

而且,是的,tf.variable_scope就像在张量板中创建好看的图形一样tf.named_scope