代码拉取完成,页面将自动刷新
#!/usr/bin/env python
"""
lr.py
learning rate scheduler
"""
import numpy as np
class LRSchedule(object):
@staticmethod
def set_lr(optimizer, lr):
for param_group in optimizer.param_groups:
param_group['lr'] = lr
@staticmethod
def constant(x, lr_init=0.1, epochs=1):
return lr_init
@staticmethod
def step(x, breaks=(150, 250)):
if x < breaks[0]:
return 0.1
elif x < breaks[1]:
return 0.01
else:
return 0.001
@staticmethod
def linear(x, lr_init=0.1, epochs=1):
return lr_init * float(epochs - x) / epochs
@staticmethod
def cyclical(x, lr_init=0.1, epochs=1):
""" Cyclical learning rate w/ annealing """
if x < 1:
# Start w/ small learning rate
return 0.05
else:
return lr_init * (1 - x % 1) * (epochs - np.floor(x)) / epochs
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。