2017-08-08 127 views
1

我一直在嘗試打印出我的模型的混亂矩陣,但未能如願。深度學習的混亂矩陣

但是,我成功地獲得了一個(7x7)混淆矩陣但是張量格式。

我是Tensorflow新手,所以請幫助我顯示張量。謝謝。

代碼:

con_mat = tf.confusion_matrix(labels=[0, 1, 2, 3, 4, 5, 6], predictions=correct, num_classes=n_classes, 
           dtype=tf.int32, name=None) 
with tf.Session(): 
    print('Confusion Matrix: \n\n', tf.Tensor.eval(con_mat, feed_dict=None, session=None)) 

輸出:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape [-1,100,88] has negative dimensions 
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[?,100,88], _device="/job:localhost/replica:0/task:0/cpu:0"]()]] 
+0

這不是你在TF中運行的東西。它應該是:'用tf.Session()as sess:print(sess.run(con_mat))'(也有其他錯誤,但是免得以基礎開始;特別是 - 錯誤與佔位符相關 - 你在哪裏使用在你的代碼中佔位符?) – lejlot

回答

0

似乎你不喂輸入佔位符值來計算tensor正確。

feeddict = {your_placeholder: value} 
with tf.Session() as sess: 
    print('Confusion Matrix: \n\n', tf.Tensor.eval(con_mat, feed_dict=feeddict, session=sess)) 
+0

所以在我的情況下,feeddict應該是{y:correct}?而y是標籤的佔位符。@Ishant Mrinal –

+0

對!那可行。 –

+0

我得到了這個錯誤,因爲正確的張量格式: 'raise TypeError('Feed的值不能是tf.Tensor對象。' TypeError:Feed的值不能是tf.Tensor對象。可接受Feeds值包括Python標量,字符串,列表,numpy ndarrays或TensorHandles.' @Ishant Mrinal,我應該怎麼做? –