Skip to content

Instantly share code, notes, and snippets.

View amqdn's full-sized avatar

Andrew Minh Nguyen amqdn

View GitHub Profile
@drscotthawley
drscotthawley / get_1cycle_schedule.py
Last active May 31, 2022 16:51
Implementation of 1cycle learning rate schedule, but without fast.ai
import numpy as np
def get_1cycle_schedule(lr_max=1e-3, n_data_points=8000, epochs=200, batch_size=40, verbose=0):
"""
Creates a look-up table of learning rates for 1cycle schedule with cosine annealing
See @sgugger's & @jeremyhoward's code in fastai library: https://github.com/fastai/fastai/blob/master/fastai/train.py
Wrote this to use with my Keras and (non-fastai-)PyTorch codes.
Note that in Keras, the LearningRateScheduler callback (https://keras.io/callbacks/#learningratescheduler) only operates once per epoch, not per batch
So see below for Keras callback