Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created January 26, 2021 17:22
Show Gist options
  • Save ntakouris/e8a29d4883c4762ea22290c32338c755 to your computer and use it in GitHub Desktop.
Save ntakouris/e8a29d4883c4762ea22290c32338c755 to your computer and use it in GitHub Desktop.
def lr_scheduler(epoch, lr, warmup_epochs=15, decay_epochs=100, initial_lr=1e-6, base_lr=1e-3, min_lr=5e-5):
if epoch <= warmup_epochs:
pct = epoch / warmup_epochs
return ((base_lr - initial_lr) * pct) + initial_lr
if epoch > warmup_epochs and epoch < warmup_epochs+decay_epochs:
pct = 1 - ((epoch - warmup_epochs) / decay_epochs)
return ((base_lr - min_lr) * pct) + min_lr
return min_lr
callbacks += [keras.callbacks.LearningRateScheduler(partial(lr_scheduler, ...), verbose=0)]
@YangJoy750
Copy link

Could you provide a example to the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment