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.1 kB

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