2017-05-27 82 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」,形狀=(1,10),D型細胞= 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,權重和偏差 – Wontonimo