Skip to content

Instantly share code, notes, and snippets.

@alessiamarcolini
Created June 7, 2018 16:04
Show Gist options
  • Save alessiamarcolini/f5f8dfe1f29cc5a6052ad0f0109e4602 to your computer and use it in GitHub Desktop.
Save alessiamarcolini/f5f8dfe1f29cc5a6052ad0f0109e4602 to your computer and use it in GitHub Desktop.
Cyclical Learning Rates - Keras
def clr(self):
cycle = np.floor(1 + self.clr_iterations / (2 * self.step_size))
x = np.abs(self.clr_iterations / self.step_size - 2 * cycle + 1)
if self.scale_mode == 'cycle':
return self.base_lr + (self.max_lr - self.base_lr) * \
np.maximum(0, (1 - x)) * self.scale_fn(cycle)
else:
return self.base_lr + (self.max_lr - self.base_lr) * \
np.maximum(0, (1 - x)) * self.scale_fn(self.clr_iterations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment