Keras accuracy does not change

The most likely reason is that the optimizer is not suited to your dataset. Here is a list of Keras optimizers from the documentation.

I recommend you first try SGD with default parameter values. If it still doesn’t work, divide the learning rate by 10. Do that a few times if necessary. If your learning rate reaches 1e-6 and it still doesn’t work, then you have another problem.

In summary, replace this line:

model.compile(loss = "categorical_crossentropy", optimizer = "adam")

with this:

from keras.optimizers import SGD
opt = SGD(lr=0.01)
model.compile(loss = "categorical_crossentropy", optimizer = opt)

and change the learning rate a few times if it doesn’t work.

If it was the problem, you should see the loss getting lower after just a few epochs.

Leave a Comment