Can model.fit be set to time out?

87 views
Skip to first unread message

stephen...@gmail.com

unread,
May 14, 2020, 9:20:28 AM5/14/20
to Keras-users
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.


Lance Norskog

unread,
May 14, 2020, 1:10:57 PM5/14/20
to stephen...@gmail.com, Keras-users
You could create a Callback object that checks the wallclock time in its callbacks. This would not quit at time T, but at the next epoch. You may be able to do "early stopping" in the middle of an epoch. You would have to copy and change the code from the EarlyStopping callback.

Cheers,

Lance Norskog

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/b70d5320-a475-406c-8dc5-145853ff2886%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA
Reply all
Reply to author
Forward
0 new messages