mindspore.experimental.optim.lr_scheduler.PolynomialLR
- class mindspore.experimental.optim.lr_scheduler.PolynomialLR(optimizer, total_iters=5, power=1.0, last_epoch=- 1)[源代码]
每个epoch,学习率通过多项式拟合来调整。当epoch大于等于 total_iters 时,学习率设置为
0
。注意,这种衰减可能与外部对于学习率的改变同时发生。学习率计算的多项式公式如下:
\[\begin{split}\begin{split} &factor = (\frac{1.0 - \frac{last\_epoch}{total\_iters}}{1.0 - \frac{last\_epoch - 1.0}{total\_iters}}) ^{power}\\ &lr = lr \times factor \end{split}\end{split}\]警告
这是一个实验性的动态学习率接口,需要和 mindspore.experimental.optim 下的接口配合使用。
- 参数:
optimizer (
mindspore.experimental.optim.Optimizer
) - 优化器实例。total_iters (int,可选) - 通过多项式拟合调整学习率的迭代次数。默认值:
5
。power (float,可选) - 多项式的幂。默认值:
1.0
。last_epoch (int,可选) - 最后一个epoch的索引。默认值:
-1
。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> from mindspore import nn >>> from mindspore.experimental import optim >>> class Net(nn.Cell): ... def __init__(self): ... super(Net, self).__init__() ... self.fc = nn.Dense(16 * 5 * 5, 120) ... def construct(self, x): ... return self.fc(x) >>> net = Net() >>> optimizer = optim.Adam(net.trainable_params(), 0.01) >>> scheduler = optim.lr_scheduler.PolynomialLR(optimizer) >>> for i in range(6): ... scheduler.step() ... current_lr = scheduler.get_last_lr() ... print(current_lr) [Tensor(shape=[], dtype=Float32, value= 0.008)] [Tensor(shape=[], dtype=Float32, value= 0.006)] [Tensor(shape=[], dtype=Float32, value= 0.004)] [Tensor(shape=[], dtype=Float32, value= 0.002)] [Tensor(shape=[], dtype=Float32, value= 0)] [Tensor(shape=[], dtype=Float32, value= 0)]