未验证 提交 962c540c 编写于 作者: T Tingquan Gao 提交者: GitHub

debug: when using Piecewise.learning_rate while total epochs < 30 (#2901)

上级 907e5f78
...@@ -255,7 +255,7 @@ class Cosine(LRBase): ...@@ -255,7 +255,7 @@ class Cosine(LRBase):
class Cyclic(LRBase): class Cyclic(LRBase):
"""Cyclic learning rate decay """Cyclic learning rate decay
Args: Args:
epochs (int): Total epoch(s). epochs (int): Total epoch(s).
step_each_epoch (int): Number of iterations within an epoch. step_each_epoch (int): Number of iterations within an epoch.
...@@ -406,11 +406,17 @@ class Piecewise(LRBase): ...@@ -406,11 +406,17 @@ class Piecewise(LRBase):
learning_rate=None, learning_rate=None,
**kwargs): **kwargs):
if learning_rate: if learning_rate:
decay_epochs = list(range(0, epochs, 30))[1:] decay_epochs = list(range(0, epochs, 30))
values = [ values = [
learning_rate * (0.1**i) learning_rate * (0.1**i) for i in range(len(decay_epochs))
for i in range(len(decay_epochs) + 1)
] ]
# when total epochs < 30, decay_epochs and values should be
# [] and [lr] respectively, but paddle dont support.
if len(decay_epochs) == 1:
decay_epochs = [epochs]
values = [values[0], values[0]]
else:
decay_epochs = decay_epochs[1:]
logger.warning( logger.warning(
"When 'learning_rate' of Piecewise has beed set, " "When 'learning_rate' of Piecewise has beed set, "
"the learning rate scheduler would be set by the rule that lr decay 10 times every 30 epochs. " "the learning rate scheduler would be set by the rule that lr decay 10 times every 30 epochs. "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册