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]

Calculates learning rate base on polynomial decay function. The learning rate for each step will be stored in a list.

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) – Number of epochs to decay over.

  • power (float) – The power of polynomial. It 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.

Raises
  • TypeError – If learning_rate or end_learning_rate or power is not a float.

  • TypeError – If total_step or step_per_epoch or decay_epoch is not an int.

  • TypeError – If update_decay_epoch is not a bool.

  • ValueError – If learning_rate or power is not greater than 0.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.nn as nn
>>>
>>> lr = 0.1
>>> end_learning_rate = 0.01
>>> total_step = 6
>>> step_per_epoch = 2
>>> decay_epoch = 2
>>> power = 0.5
>>> lr = nn.polynomial_decay_lr(lr, end_learning_rate, total_step, step_per_epoch, decay_epoch, power)
>>> net = nn.Dense(2, 3)
>>> optim = nn.SGD(net.trainable_params(), learning_rate=lr)