Created
September 13, 2017 19:08
-
-
Save ikhlestov/8fe9fbef9766534622a3117352990f64 to your computer and use it in GitHub Desktop.
pytorch: learning rate scheduler, train flag, random seed
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
# scheduler example | |
from torch.optim import lr_scheduler | |
optimizer = torch.optim.SGD(model.parameters(), lr=0.01) | |
scheduler = lr_scheduler.StepLR(optimizer, step_size=30, gamma=0.1) | |
for epoch in range(100): | |
scheduler.step() | |
train() | |
validate() | |
# Train flag can be updated with boolean | |
# to disable dropout and batch norm learning | |
model.train(True) | |
# execute train step | |
model.train(False) | |
# run inference step | |
# CPU seed | |
torch.manual_seed(42) | |
# GPU seed | |
torch.cuda.manual_seed_all(42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment