web-dev-qa-db-ja.com

クロスエントロピー損失を計算するときのテンソルフローエラー

次のエラーが表示されます

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。

なぜアイデアがありますか?

15
anamar

_input_y_を定義しているように聞こえます。これはtf.placeholder()であると想定していますが、タイプ_tf.int32_を持っているとみなされます。これを_tf.float32_に変更するか、 casttf.cast(input_y, tf.float32)またはtf.to_float(input_y)を追加します。

23
mrry