-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TimeStopping callback #1625
Comments
@kylemcdonald 👍 yes, this is super helpful. Especially if you run your jobs on a HPC cluster where a 24h job limit applies ;-) I would even add class TimedStopping(Callback):
'''Stop training when enough time has passed.
# Arguments
seconds: maximum time before stopping.
safety_factor: stop safety_factor * average_time_per_epoch earlier
verbose: verbosity mode.
'''
def __init__(self, seconds=None, safety_factor=1, verbose=0):
super(Callback, self).__init__()
self.start_time = 0
self.safety_factor = safety_factor
self.seconds = seconds
self.verbose = verbose
self.time_logs = []
def on_train_begin(self, logs={}):
self.start_time = time.time()
def on_epoch_end(self, epoch, logs={}):
elapsed_time = time.time() - self.start_time
self.time_logs.append(elapsed_time)
avg_elapsed_time = float(sum(self.time_logs)) / \
max(len(self.time_logs), 1)
print(" ", self.seconds - self.safety_factor * avg_elapsed_time)
if elapsed_time > self.seconds - self.safety_factor * avg_elapsed_time:
self.model.stop_training = True
if self.verbose:
print('Stopping after %s seconds.' % self.seconds) are submitting a PR? |
Please consider adding it to the contrib repo: https://github.com/farizrahman4u/keras-contrib |
@fchollet didn't know about contrib. Maybe it |
Thanks @fchollet closing this and moving to keras-team/keras-contrib#87 |
I've been using this callback for stopping training after a fixed period of time, useful when testing different architectures consecutively. Is it worth contributing?
One thing I noticed was
self.model.stop_training
only stops the model after an epoch, but with some training where the epochs are very long you might want to stop after a batch.The text was updated successfully, but these errors were encountered: