# Saving a different model for every epoch Keras

As part of a project I am currently running a CNN for classifying images. Right now I am training with 50 epochs. I have noticed that after around 20-30 epochs I reach the highest accuracy and then the loss starts to increase significantly. I thought about using Early Stopping but my model loss has a lot of zig-zagging so I think it would be difficult to find the right patience argument to use. I think it would be easier to just save a model for every epoch so I can manually select the one with the highest accuracy. Is this possible in Keras?

Saving many models definitely possible.

# serialize model to JSON
model_json = model.to_json()
with open("model.json", "w") as json_file:
json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("model.h5")
print("Saved model to disk")

# later...

# load json and create model
json_file = open('model.json', 'r')