-
-
Save Shubhamai/668380319478e696905064ec2b2f7d8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LR_START = 0.00001 | |
LR_MAX = 0.0001 | |
LR_MIN = 0.00001 | |
LR_RAMPUP_EPOCHS = 15 | |
LR_SUSTAIN_EPOCHS = 3 | |
LR_EXP_DECAY = .8 | |
EPOCHS = 100 | |
def lrfn(epoch): | |
if epoch < LR_RAMPUP_EPOCHS: | |
lr = (LR_MAX - LR_START) / LR_RAMPUP_EPOCHS * epoch + LR_START | |
elif epoch < LR_RAMPUP_EPOCHS + LR_SUSTAIN_EPOCHS: | |
lr = LR_MAX | |
else: | |
lr = (LR_MAX - LR_MIN) * LR_EXP_DECAY**(epoch - LR_RAMPUP_EPOCHS - LR_SUSTAIN_EPOCHS) + LR_MIN | |
return lr | |
lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=True) | |
rng = [i for i in range(EPOCHS)] | |
y = [lrfn(x) for x in rng] | |
plt.plot(rng, y) | |
print("Learning rate schedule: {:.3g} to {:.3g} to {:.3g}".format(y[0], max(y), y[-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment