You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.nn.PolynomialDecayLR.rst 2.2 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. mindspore.nn.PolynomialDecayLR
  2. ====================================
  3. .. py:class:: mindspore.nn.PolynomialDecayLR(learning_rate, end_learning_rate, decay_steps, power, update_decay_steps=False)
  4. 基于多项式衰减函数计算学习率。
  5. 对于当前step,计算decayed_learning_rate[current_step]的公式为:
  6. .. math::
  7. decayed\_learning\_rate[current\_step] = &(learning\_rate - end\_learning\_rate) *\\
  8. &(1 - tmp\_step / tmp\_decay\_steps)^{power}\\
  9. &+ end\_learning\_rate
  10. 其中,
  11. .. math::
  12. tmp\_step=min(current\_step, decay\_steps)
  13. 如果 `update_decay_steps` 为true,则每 `decay_steps` 更新 `tmp_decay_step` 的值。公式为:
  14. .. math::
  15. tmp\_decay\_steps = decay\_steps * ceil(current\_step / decay\_steps)
  16. **参数:**
  17. - **learning_rate** (float) - 学习率的初始值。
  18. - **end_learning_rate** (float) - 学习率的最终值。
  19. - **decay_steps** (int) - 用于计算衰减学习率的值。
  20. - **power** (float) - 用于计算衰减学习率的值。该参数必须大于0。
  21. - **update_decay_steps** (bool) - 如果为True,则学习率每 `decay_steps` 次衰减一次。默认值:False。
  22. **输入:**
  23. - **global_step** (Tensor):当前step数。
  24. **输出:**
  25. Tensor。当前step的学习率值, shape为 :math:`()`。
  26. **异常:**
  27. - **TypeError** - `learning_rate`, `end_learning_rate` 或 `power` 不是float。
  28. - **TypeError** - `decay_steps` 不是int或 `update_decay_steps` 不是bool。
  29. - **ValueError** - `end_learning_rate` 小于0或 `decay_steps` 小于1。
  30. - **ValueError** - `learning_rate` 或 `power` 小于或等于0。
  31. **支持平台:**
  32. ``Ascend`` ``GPU``
  33. **样例:**
  34. >>> import mindspore
  35. >>> from mindspore import Tensor, nn
  36. >>>
  37. >>> learning_rate = 0.1
  38. >>> end_learning_rate = 0.01
  39. >>> decay_steps = 4
  40. >>> power = 0.5
  41. >>> global_step = Tensor(2, mindspore.int32)
  42. >>> polynomial_decay_lr = nn.PolynomialDecayLR(learning_rate, end_learning_rate, decay_steps, power)
  43. >>> result = polynomial_decay_lr(global_step)
  44. >>> print(result)
  45. 0.07363961