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
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.