Skip to content Skip to sidebar Skip to footer

Why Am I Getting Keras Shape Mismatch?

I am following a Keras mnist example for beginners. I have tried to change the labels to suit my own data which has 3 distinct text classifications. I am using 'to_categorical' to

Solution 1:

You need to use categorical_crossentropy instead of sparse_categorical_crossentropy as loss since your labels are one hot encoded.

Alternatively, you can use sparse_categorical_crossentropy if you do not one hot encode the labels. In that case, the labels should have shape (batch_size, 1).

Solution 2:

Use the loss,

loss = keras.losses.categorical_crossentropy

when the target label contain multiple instances.

Post a Comment for "Why Am I Getting Keras Shape Mismatch?"