piecewise_decay

paddle.fluid.layers.piecewise_decay(boundaries, values)[源代码]

对初始学习率进行分段衰减。

该算法可用如下代码描述。

  1. boundaries = [10000, 20000]
  2. values = [1.0, 0.5, 0.1]
  3. if step < 10000:
  4. learning_rate = 1.0
  5. elif 10000 <= step < 20000:
  6. learning_rate = 0.5
  7. else:
  8. learning_rate = 0.1

参数

  • boundaries(list) - 代表步数的数字
  • values(list) - 学习率的值,不同的步边界中的学习率值

返回

衰减的学习率

代码示例

  1. import paddle.fluid as fluid
  2. boundaries = [10000, 20000]
  3. values = [1.0, 0.5, 0.1]
  4. optimizer = fluid.optimizer.Momentum(
  5. momentum=0.9,
  6. learning_rate=fluid.layers.piecewise_decay(boundaries=boundaries, values=values),
  7. regularization=fluid.regularizer.L2Decay(1e-4))