(learning_rate, step_each_epoch, epochs=120)
return lr
Applies cosine decay to the learning rate.
  lr = 0.05 * (math.cos(epoch * (math.pi / 120)) + 1)
  decrease lr for every mini-batch and start with warmup.
Applies cosine decay to the learning rate.
  lr = 0.05 * (math.cos(epoch * (math.pi / 120)) + 1)
  decrease lr for every mini-batch and start with warmup.
Applies cosine decay to the learning rate . lr = 0 . 05 * ( math . cos ( epoch * ( math . pi / 120 )) + 1 ) decrease lr for every mini - batch and start with warmup .
def cosine_decay_with_warmup(learning_rate, step_each_epoch, epochs=120):
    """Applies cosine decay to the learning rate.
  lr = 0.05 * (math.cos(epoch * (math.pi / 120)) + 1)
  decrease lr for every mini-batch and start with warmup.
  """
    from paddle.fluid.layers.learning_rate_scheduler import _decay_step_counter
    global_step = _decay_step_counter()
    lr = fluid.layers.tensor.create_global_var(
        shape=[1],
        value=0.0,
        dtype='float32',
        persistable=True,
        name="learning_rate")

    warmup_epoch = fluid.layers.fill_constant(
        shape=[1], dtype='float32', value=float(5), force_cpu=True)

    epoch = ops.floor(global_step / step_each_epoch)
    with fluid.layers.control_flow.Switch() as switch:
        with switch.case(epoch < warmup_epoch):
            decayed_lr = learning_rate * (global_step /
                                          (step_each_epoch * warmup_epoch))
            fluid.layers.tensor.assign(input=decayed_lr, output=lr)
        with switch.default():
            decayed_lr = learning_rate * \
              (ops.cos((global_step - warmup_epoch * step_each_epoch) * (math.pi / (epochs * step_each_epoch))) + 1)/2
            fluid.layers.tensor.assign(input=decayed_lr, output=lr)
    return lr
def cosine_decay_with_warmup ( learning_rate , step_each_epoch , epochs = 120 ) : from paddle . fluid . layers . learning_rate_scheduler import _decay_step_counter global_step = _decay_step_counter ( ) lr = fluid . layers . tensor . create_global_var ( shape = [ 1 ] , value = 0.0 , dtype = 'float32' , persistable = True , name = "learning_rate" ) warmup_epoch = fluid . layers . fill_constant ( shape = [ 1 ] , dtype = 'float32' , value = float ( 5 ) , force_cpu = True ) epoch = ops . floor ( global_step / step_each_epoch ) with fluid . layers . control_flow . Switch ( ) as switch : with switch . case ( epoch < warmup_epoch ) : decayed_lr = learning_rate * ( global_step / ( step_each_epoch * warmup_epoch ) ) fluid . layers . tensor . assign ( input = decayed_lr , output = lr ) with switch . default ( ) : decayed_lr = learning_rate * ( ops . cos ( ( global_step - warmup_epoch * step_each_epoch ) * ( math . pi / ( epochs * step_each_epoch ) ) ) + 1 ) / 2 fluid . layers . tensor . assign ( input = decayed_lr , output = lr ) return lr