mindspore.nn.inverse_decay_lr

mindspore.nn.inverse_decay_lr(learning_rate, decay_rate, total_step, step_per_epoch, decay_epoch, is_stair=False)[source]

Calculate learning rate base on inverse-time decay function.

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

\[decayed\_learning\_rate[i] = learning\_rate / (1 + decay\_rate * current\_epoch / decay\_epoch)\]

Where \(current\_epoch=floor(\frac{i}{step\_per\_epoch})\).

Parameters
  • learning_rate (float) – The initial value of learning rate.

  • decay_rate (float) – The decay 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.

  • is_stair (bool) – If true, learning rate is decayed once every decay_epoch times. Default: False.

Returns

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

Examples

>>> learning_rate = 0.1
>>> decay_rate = 0.5
>>> total_step = 6
>>> step_per_epoch = 1
>>> decay_epoch = 1
>>> output = inverse_decay_lr(learning_rate, decay_rate, total_step, step_per_epoch, decay_epoch, True)
>>> print(output)
[0.1, 0.06666666666666667, 0.05, 0.04, 0.03333333333333333, 0.028571428571428574]