2

I am using Keras 2.2.4 and normally I use the Keras EarlyStopping callback to halt training while ensuring that the best weights observed during that training are returned. So, I have something like the following:

stop_early = keras.callbacks.EarlyStopping(
    monitor              = 'val_loss',
    min_delta            = 0.0001,
    patience             = 300,
    verbose              = 1,
    mode                 = 'auto',
    baseline             = None,
    restore_best_weights = True
)

What would be some way I could get Keras to halt the training and to return the best weights, as though the criteria given to EarlyStopping had been met? I have in mind the idea that there could be some callback a bit like EarlyStopping that checks routinely for the existence of some file, e.g. safeword, at the working directory. How might this or similar be done?

1 Answers1

1

The simplest and probably the most robust solution would be to just use the ModelCheckpoint callback with save_best_only=True and implement the halting separately depending on... well, whatever you need, really.

For a program running in CLI, you don't really need anything special, just throw a KeyboardInterrupt with Ctrl+C. Anything more fanciful, well, that depends on what you have in mind; one way or another you'll need to have something listening to I/O events asynchronously or after each epoch - but that part of the question is probably better suited for StackOverflow.

jkm
  • 2,165