mindspore.nn.polynomial_decay_lr

mindspore.nn.polynomial_decay_lr(learning_rate, end_learning_rate, total_step, step_per_epoch, decay_epoch, power, update_decay_epoch=False)[source]

Calculate learning rate base on polynomial decay function.

For the i-th step, the formula of computing decayed_learning_rate[i] is:

\[decayed\_learning\_rate[i] = (learning\_rate - end\_learning\_rate) * (1 - tmp\_epoch / tmp\_decay\_epoch)^{power} + end\_learning\_rate\]

Where:

\[tmp\_epoch = min(current\_epoch, decay\_epoch)\]
\[current\_epoch=floor(\frac{i}{step\_per\_epoch})\]
\[tmp\_decay\_epoch = decay\_epoch\]

If update_decay_epoch is true, update the value of tmp_decay_epoch every epoch. The formula is:

\[tmp\_decay\_epoch = decay\_epoch * ceil(current\_epoch / decay\_epoch)\]
Parameters
  • learning_rate (float) – The initial value of learning rate.

  • end_learning_rate (float) – The end value of learning rate.

  • total_step (int) – The total number of steps.

  • step_per_epoch (int) – The number of steps in per epoch.

  • decay_epoch (int) – A value used to calculate decayed learning rate.

  • power (float) – A value used to calculate decayed learning rate. This parameter must be greater than 0.

  • update_decay_epoch (bool) – If true, update decay_epoch. Default: False.

Returns

list[float]. The size of list is total_step.

Examples

>>> learning_rate = 0.1
>>> end_learning_rate = 0.01
>>> total_step = 6
>>> step_per_epoch = 2
>>> decay_epoch = 2
>>> power = 0.5
>>> r = polynomial_decay_lr(learning_rate, end_learning_rate, total_step, step_per_epoch, decay_epoch, power)
>>> print(r)
[0.1, 0.1, 0.07363961030678928, 0.07363961030678928, 0.01, 0.01]