2017-05-27 20 views
1
#file for inputing the data for testing 
from scipy import ndimage 
image_file='test.png' 
image_data = ndimage.imread(image_file).astype(float) 
image_data = image_data.reshape((-1, image_size * image_size)).astype(np.float32) 
rst = tf.Graph() 
with rst.as_default(): 
    result = tf.matmul(image_data, weights) + biases 
    picko=tf.nn.softmax(result) 
with tf.Session(graph=rst) as rsts: 
    tf.global_variables_initializer().run() 
    predictions = rsts.run([picko]) 

上記のコードを実行すると、以下のエラーが表示されます。手動で解決できない解決策を提案してください。TensorFlow:テンソルはこのグラフの要素ではありません

ValueError:フェッチ引数をテンソルとして解釈できません。 (テンソルテンソル(Softmax_4:0、shape =(1,10)、dtype = float32)は、このグラフの要素ではありません)。

答えて

0

このコードを試してください。

主な違いは、コード全体がデフォルトグラフを使用し、作成されたグラフを使用しないことです。

#file for inputing the data for testing 
from scipy import ndimage 
image_file = 'test.png' 
image_data = ndimage.imread(image_file).astype(float) 
image_data = image_data.reshape((-1, image_size * image_size)).astype(np.float32)  
result = tf.matmul(image_data, weights) + biases 
picko = tf.nn.softmax(result) 
with tf.Session() as rsts: 
    tf.global_variables_initializer().run() 
    predictions = rsts.run([picko]) 
+0

あなたのコードは、問題が発生する可能性があり理由は、最初、デフォルトとして使用すると、スコープということですが、あなたはテンソルを置いているところ基本的に混合、それ外に他のテンソルを定義しました。 – Wontonimo

+0

グラフをセッションの引数として渡していますが、それをどのように使用していますか? – Kanwarkajla

+0

代わりに、グラフを定義し、image_data、weights、およびbiasなどのテンソルをすべて定義します。 – Wontonimo

関連する問題