I have a Keras Autoencoder-decoder that I have wrapped the model.fit call with a try: .... except KeyboardInterrupt:
It works nicely, I can watch the progress and interrupt the training, allowing it to go on with the rest of the application.
I would like to set a timeout. (e.g. run for 20 minutes or until the max_epoch is reached whichever is sooner.)
Alternatively is there a way I could get a spawned thread (timer) to raise an exception in the parent?
try:
thread = Threading.thread( MyTimer )
model.fit(.......
except KeyboardInterrupt:
print( 'Training was aborted early')
With something like:
def MyTimer():
x = time.clock() + 1200
while(True):
if ( time.clock() > x ):
raise KeyboardInterrupt
This however does not actually work.