Keras Dense layer shape error

前端 未结 1 1554
醉梦人生
醉梦人生 2020-12-21 17:05

I am using keras to create a LSTM model. While training, I am getting this error.

ValueError: Error when checking target: expected dense_4 to have shape (1,) b

相关标签:
1条回答
  • 2020-12-21 17:42

    Ok, I found the issue. I am posting this as answer so that it can help others also who is facing the same issue.

    It was not the layer configuration but the wrong loss function.

    I was using sparse_categorical_crossentropy as loss where labels must have the shape [batch_size] and the dtype int32 or int64. I have changed is to categorical_crossentropy which expect label of [batch_size, num_classes].

    Error message thrown by keras was misleading.

    0 讨论(0)
提交回复
热议问题