mindspore.nn.exponential_decay_lr
- mindspore.nn.exponential_decay_lr(learning_rate, decay_rate, total_step, step_per_epoch, decay_epoch, is_stair=False)[source]
Calculates learning rate base on exponential 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 * decay\_rate^{\frac{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) – Number of epochs to decay over.
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.
- Raises
TypeError – If total_step or step_per_epoch or decay_epoch is not an int.
TypeError – If is_stair is not a bool.
TypeError – If learning_rate or decay_rate is not a float.
ValueError – If learning_rate or decay_rate is less than or equal to 0.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.nn as nn >>> >>> learning_rate = 0.1 >>> decay_rate = 0.9 >>> total_step = 6 >>> step_per_epoch = 2 >>> decay_epoch = 1 >>> output = nn.exponential_decay_lr(learning_rate, decay_rate, total_step, step_per_epoch, decay_epoch) >>> print(output) [0.1, 0.1, 0.09000000000000001, 0.09000000000000001, 0.08100000000000002, 0.08100000000000002]