未验证 提交 0e5de2a2 编写于 作者: T Tingquan Gao 提交者: GitHub

support to specify priority about steps and epochs in LinearWarmup (#8540)

for uapi
上级 a3e9c925
...@@ -165,17 +165,20 @@ class LinearWarmup(object): ...@@ -165,17 +165,20 @@ class LinearWarmup(object):
of `epochs` is higher than `steps`. Default: None. of `epochs` is higher than `steps`. Default: None.
""" """
def __init__(self, steps=500, start_factor=1. / 3, epochs=None): def __init__(self, steps=500, start_factor=1. / 3, epochs=None, epochs_first=True):
super(LinearWarmup, self).__init__() super(LinearWarmup, self).__init__()
self.steps = steps self.steps = steps
self.start_factor = start_factor self.start_factor = start_factor
self.epochs = epochs self.epochs = epochs
self.epochs_first = epochs_first
def __call__(self, base_lr, step_per_epoch): def __call__(self, base_lr, step_per_epoch):
boundary = [] boundary = []
value = [] value = []
warmup_steps = self.epochs * step_per_epoch \ if self.epochs_first and self.epochs is not None:
if self.epochs is not None else self.steps warmup_steps = self.epochs * step_per_epoch
else:
warmup_steps = self.steps
warmup_steps = max(warmup_steps, 1) warmup_steps = max(warmup_steps, 1)
for i in range(warmup_steps + 1): for i in range(warmup_steps + 1):
if warmup_steps > 0: if warmup_steps > 0:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册