2017-04-11 9 views
0

変数のネームスペースを管理するためにname_scopeを使用していますので、テンソルボードでうまく表示できます。しかし、私は奇妙な何かを見つける、name_scopeは、tf.get_variableによって作成された変数に接頭辞を追加しないでください。 だからコードはエラーを発生させる:テンソルボードについてname_scope

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: Variable w already exists, disallowed.

は、私が代わりにname_scopeのvariable_scopeを使用することはできますか?そしてtensorboardはvariable_scopeで動作しますか?

答えて

6

tf.name_scopeは、範囲内で定義されたの操作の接頭辞を定義します。

tf.variable_scopeは、操作のプレフィックスと、スコープ内で定義された変数を定義します。

別の変数と同じ名前の変数を別のスコープで作成する場合は、tf.variable_scopeを使用する必要があります。

tf.name_scopeは、コンテキストをうまく定義するためにカスタム操作を定義するために使用されます。

個人的には、私はほとんどいつもtf.variable_scopeを使用しています。

さらに、tf.variable_scopeは、正確にテンソルボードで良好なグラフを作成します。tf.named_scope

関連する問題