TensorFlow 中的 tf.train.exponential_decay() 指数衰减法

exponential_decay(learning_rate, global_step, decay_steps, decay_rate, staircase=False, name=None)

使用方式为

tf.train.exponential_decay( )

在 Tensorflow 中,exponential_decay()是应用于学习率的指数衰减函数。

在训练模型时,通常建议随着训练的进行逐步降低学习率。该函数需要`global_step`值来计算衰减的学习速率。

该函数返回衰减后的学习率。该函数的计算方程式如下

参数:

learning_rate - 初始学习率

global_step - 用于衰减计算的全局步骤。 一定不为负数。喂入一次 BACTH_SIZE 计为一次 step

decay_steps - 衰减速度,一定不能为负数,每间隔decay_steps次更新一次learning_rate值

decay_rate - 衰减系数,衰减速率,其具体意义参看函数计算方程。

decay_rate:指数衰减参数(对应α^t中的α)

decay_steps为衰减速度。

衰减速度,一定不能为负数。

learning rate更新的step周期,即每隔多少step更新一次learning rate的值

learning_rate, global_step, decay_steps, decay_rate, staircase=False, name=None

如果参数`staircase`是'True`,则`global_step / decay_steps`是整数除法,衰减学习率遵循阶梯函数。

global_step = tf.Variable(0, trainable=False)
starter_learning_rate = 0.1
learning_rate = tf.train.exponential_decay(starter_learning_rate, global_step,
100000, 0.96, staircase=True)
# Passing global_step to minimize() will increment it at each step.
learning_step = (
tf.train.GradientDescentOptimizer(learning_rate)
.minimize(...my loss..., global_step=global_step)
)

 

 

通过tf.train.exponential_decay函数实现指数衰减学习率。

步骤:1.首先使用较大学习率(目的:为快速得到一个比较优的解);

    2.然后通过迭代逐步减小学习率(目的:为使模型在训练后期更加稳定);

猜你喜欢

转载自www.cnblogs.com/gengyi/p/9898960.html