Skip to content

Commit

Permalink
StopOnLR message when stop
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanollion committed May 3, 2024
1 parent 8f7fdfa commit 5d8fc76
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions distnet_2d/utils/callbacks.py
Expand Up @@ -61,16 +61,19 @@ def _tmp_path(self, path):
split = os.path.splitext(path)
return split[0] + "_tmp" + split[1]


class StopOnLR(Callback):
def __init__( self, min_lr, **kwargs, ):
super().__init__()
self.min_lr = min_lr

def on_epoch_end(self, epoch, logs={}):
def on_epoch_end(self, epoch, logs=None):
lr = backend.get_value(self.model.optimizer.lr)
if(lr <= self.min_lr):
if lr <= self.min_lr:
print(f"Learning rate {lr} <= {self.min_lr} : training will be stopped", flush=True)
self.model.stop_training = True


class EpsilonCosineDecayCallback(Callback):
"""Reduce optimizer epsilon parameter.
Args:
Expand Down

0 comments on commit 5d8fc76

Please sign in to comment.