add cosine decay

This commit is contained in:
tink2123 2020-06-10 15:41:16 +08:00
parent ae2589b4d9
commit 15ae5176a3
2 changed files with 14 additions and 0 deletions

View File

@ -41,3 +41,7 @@ Optimizer:
base_lr: 0.0005 base_lr: 0.0005
beta1: 0.9 beta1: 0.9
beta2: 0.999 beta2: 0.999
decay:
function: cosine_decay
step_each_epoch: 20
total_epoch: 1000

View File

@ -28,6 +28,16 @@ def AdamDecay(params, parameter_list=None):
base_lr = params['base_lr'] base_lr = params['base_lr']
beta1 = params['beta1'] beta1 = params['beta1']
beta2 = params['beta2'] beta2 = params['beta2']
if 'decay' in params:
params = params['decay']
decay_mode = params['function']
step_each_epoch = params['step_each_epoch']
total_epoch = params['total_epoch']
if decay_mode == "cosine_decay":
base_lr = fluid.layers.cosine_decay(
learning_rate=base_lr,
step_each_epoch=step_each_epoch,
epochs=total_epoch)
optimizer = fluid.optimizer.Adam( optimizer = fluid.optimizer.Adam(
learning_rate=base_lr, learning_rate=base_lr,
beta1=beta1, beta1=beta1,