0
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

Saving many models definitely possible.

Please find below code snippet:

# 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')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("model.h5")
print("Loaded model from disk")

For detailed reference:Save&Load Keras model

Note: Please append epoch value with the file name, so that you have all different trained model.s

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.