【问题标题】:Decaying the learning rate from the 100th epoch从第 100 个 epoch 开始衰减学习率
【发布时间】:2021-03-19 20:45:13
【问题描述】:

知道

learning_rate = 0.0004
optimizer = torch.optim.Adam(
    model.parameters(),
    lr=learning_rate, betas=(0.5, 0.999)
)

有没有办法从第 100 个 epoch 开始衰减学习率?

这是一个好习惯吗:

decayRate = 0.96
my_lr_scheduler = torch.optim.lr_scheduler.ExponentialLR(optimizer=my_optimizer, gamma=decayRate)

【问题讨论】:

  • 请澄清您所说的“好的解决方案”是什么意思;你的意思是代码可以工作,还是说这是很好的 ML 实践?第一个问题是这里的主题,但第二个不是 - 请注意machine-learning tag info 中的介绍和 NOTE
  • @desertnaut 我改变了我的问题
  • 但现在看起来像两个问题,而且它们之间基本上不相关。

标签: python machine-learning pytorch epoch learning-rate


【解决方案1】:
from torch.optim.lr_scheduler import MultiStepLR

# reduce the learning rate by 0.1 after epoch 100
scheduler = MultiStepLR(optimizer, milestones=[100,], gamma=0.1)

更多信息请参考:MultiStepLR

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多