2016-12-03 6 views
0

スコープの名前付けで自動列挙がどのように機能するのかを理解するのに苦労しています。たとえば、次のよう:0:TensorFlowスコープ名の列挙

with tf.variable_scope("foo"): 
    with tf.variable_scope("bar") as scope: 
     v = tf.get_variable("v", [1]) 

v.name のfoo /バー/ Vへセットを持つ変数を作成します。

変数を再利用すると、再びfoo/bar/v:0になります。別の変数を使用すると、他の変数になります。 foo/bar/x:0

誰かがその列挙子の目的私に説明してもらえ:0および/バー/ X fooのような名前で終わるために、私は何をすべきを教えてください:1

答えて

0

接尾辞:0は、Tensorflow操作の出力引数のインデックスを示します。フードの下では、get_variableVariable opを使用しますが、出力は1つだけです。したがって、get_variableを使用して定義された変数の接尾辞は:0にしかなりません。おそらく、これは一例で明らかにすることができる。

import tensorflow as tf 
import numpy as np 

tf.reset_default_graph() 

# First we instantiate a tensor using get_variable 
v = tf.get_variable("v", [1]) 
print("operation used is {}".format(v.op.op_def.name)) 
print("The output tensor is named {}".format(v.name)) 
print() 

# Now we instantiate two more tensors using split. 
# We'll try to use the same name but Tensorflow will add the suffix "_1". 
# Furthermore Tensorflow will use :[suffix] to indicate the index of the output. 
v = tf.split(1, 2, tf.constant(np.random.randn(10, 4)), name='v') 
print("length of v is {}".format(len(v))) 
print("operation used is {}".format(v[0].op.op_def.name)) 
print("The first and second outputs are named {} and {} respectively".format(v[0].name, v[1].name)) 

結果の出力:

operation used is Variable 
The output tensor is named v:0 

length of v is 2 
operation used is Split 
The first and second outputs are named v_1:0 and v_1:1 respectively 
+0

偉大な説明、ありがとうございました! –

関連する問題