Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does interrupting keras training in a Jupyter notebook save the training?

So, I was working on a machine learning project using a Jupyter Notebook and Keras, and I started training. I came back a few hours later, only to realize that I had accidentally set the epochs to a really high number.

I'm wondering, if I stop running the cell (send a KeyboardInterrupt), will the whole training be canceled? Or will the weights from the epoch I was currently on still be saved?

I can still access the model from the next cell.

like image 728
Oliver Ni Avatar asked Nov 15 '18 04:11

Oliver Ni


2 Answers

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. To test this, evaluate the model's prediction accuracy.

Note that, if you continue training the model, a KeyboardInterrupt restarts the epoch counter. That will effect any callbacks that rely on the epoch number.

like image 162
g-eoj Avatar answered Oct 05 '22 17:10

g-eoj


If you have not defined a ModelCheckpoint callback or some custom model saver callback then the answer is no.

Next time you should include the ModelCheckpoint callback, so at every epoch your model will be saved, and you can restore it

like image 29
Gabe Avatar answered Oct 05 '22 16:10

Gabe