There seems to be a way to do it in tensorflow: Keyboard interrupt tensorflow run and save at that point
Is there something like this in Keras?
You can use model. stop_training parameter to stop the training.
The trained model will still be in memory, in the state it was in when the KeyboardInterrupt happened. As long as the Python kernel isn't stopped or the model isn't reinstantiated, you can continue to use the trained model.
You could catch the KeyboardInterrupt
exception and save the model within the except
block:
save_path = './keras-saves/_latest.ckpt'
try:
model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs)
except KeyboardInterrupt:
model.save(save_path)
print('Output saved to: "{}./*"'.format(save_path))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With