2016-02-13 119 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