mindspore.nn.piecewise_constant_lr

mindspore.nn.piecewise_constant_lr(milestone, learning_rates)[source]

Get piecewise constant learning rate.

Calculate learning rate by given milestone and learning_rates. Let the value of milestone be \((M_1, M_2, ..., M_N)\) and the value of learning_rates be \((x_1, x_2, ..., x_N)\). N is the length of milestone. Let the output learning rate be y.

\[y[i] = x_t,\ for\ i \in [M_{t-1}, M_t)\]
Parameters
  • milestone (Union[list[int], tuple[int]]) – A list of milestone. This list is a monotone increasing list. Every element is a milestone step, and must be greater than 0.

  • learning_rates (Union[list[float], tuple[float]]) – A list of learning rates.

Returns

list[float]. The size of list is \(M_N\).

Examples

>>> milestone = [2, 5, 10]
>>> learning_rates = [0.1, 0.05, 0.01]
>>> output = piecewise_constant_lr(milestone, learning_rates)
>>> print(output)
[0.1, 0.1, 0.05, 0.05, 0.05, 0.01, 0.01, 0.01, 0.01, 0.01]