Created
October 25, 2019 09:56
-
-
Save hatzel/8965ebf1231e3cf3c67caecbbb028dec to your computer and use it in GitHub Desktop.
Quickly Visualize PyTorch Learning Schedulers
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
import torch | |
from torch.optim.lr_scheduler import CosineAnnealingLR | |
from torch.optim import SGD | |
import matplotlib.pyplot as plt | |
STEPS = 100 | |
optimizer = SGD([torch.tensor(1)], lr=1) | |
# Use a scheduler of your choice below. | |
# Great for debugging your own schedulers! | |
scheduler = CosineAnnealingLR(optimizer, STEPS) | |
lrs = [] | |
for _ in range(100): | |
optimizer.step() | |
lrs.append(scheduler.get_lr()) | |
scheduler.step() | |
plt.plot(lrs) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code!