2016-02-13 122 views
9

,當我得到以下錯誤Tensorflow誤差計算交叉熵損失

ValueError: Tensor conversion requested dtype float32 for Tensor with dtype int32: 'Tensor("Placeholder_1:0", shape=TensorShape([Dimension(128), Dimension(2)]), dtype=int32)' 

,當我試圖計算交叉熵損失

losses = tf.nn.softmax_cross_entropy_with_logits(scores, input_y) 

我使用Python 3.4.3。

任何想法爲什麼?

回答

16

聽起來像你已經定義了input_y-我假設它是一個tf.placeholder()-有tf.int32類型。請將其更改爲tf.float32或添加casttf.cast(input_y, tf.float32)tf.to_float(input_y)

+0

謝謝,鑄造解決了這個問題。 – anamar

+0

我在tflearn中找不到cast或to_float,我們必須導入哪個模塊? – f3n1Xx

+0

'tf.cast()'和'tf.to_float()'是TensorFlow函數,所以你可以使用'import tensorflow as tf'來獲得它們。 – mrry