2017-06-01 51 views
0

我想用KL散度來計算我的網絡的精度。預測是一個k維概率向量,它應該與相同維度的黃金標準概率分佈進行比較。 我嘗試這樣做:Tensorflow:KL分類用於分類概率分佈

corr_subj_test = tf.contrib.distributions.kl(pred_subj, y) 
accr_subj_test = tf.reduce_mean(corr_subj_test) 

但最終得到以下錯誤:

NotImplementedError: No KL(dist_a || dist_b) registered for dist_a type Tensor and dist_b type Tensor

回答

1

檢查tensorflow github和其他一些問題,讓同NotImplementedError錯誤(如this one)似乎kl()方法目前不接受參數類型的特定組合。

如果可能的話,你可以通過你的數據在kl()它接受(可能將您的數據,實現左右)的數據類型。**

您也可以嘗試將其發佈在tensorflow issues討論有關你的問題。

** 編輯:

由於提出並得到答案的問題this解釋,您可以通過使用交叉熵與替代softmax_cross_entropy_with_logits方法,這樣得到您想要的結果:

newY = pred_subj/y 
crossE = tf.nn.softmax_cross_entropy_with_logits(pred_subj, newY) 
accr_subj_test = tf.reduce_mean(-crossE) 
+0

加強與其他選擇的答案 – DarkCygnus