tf.train.exponential_decay是tensflow1.X版本的2.版本使用以下语句
tf.compat.v1.train.exponential_decay
将指数衰减应用于学习率。
tf.compat.v1.train.exponential_decay(
learning_rate, global_step, decay_steps, decay_rate, staircase=
训练模型时,通常建议随着训练的进行降低学习率。此函数将指数衰减函数应用于提供的初始学习率。它需要一个global_step
值来计算衰减的学习率。您只需传递一个TensorFlow变量,即可在每个训练步骤中增加该变量。
该函数返回衰减的学习率。计算公式为:
decayed_learning_rate = learning_rate *
decay_rate ^ (global_step / decay_steps)
如果参数staircase
为True
,global_step / decay_steps
则为整数除法,并且衰减的学习率遵循阶梯函数。
示例:以0.96为底,每100000步衰减一次:
...
global_step = tf.Variable(0, trainable=False)
starter_learning_rate = 0.1
learning_rate = tf.compat.v1.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.compat.v1.train.GradientDescentOptimizer(learning_rate)
.minimize(...my loss..., global_step=global_step)
)
ARGS
learning_rate | 标量float32 或float64 Tensor Python数。初始学习率。 |
global_step | 标量int32 或int64 Tensor Python数。用于衰减计算的全局步骤。不能为负。 |
decay_steps | 标量int32 或int64 Tensor Python数。必须是积极的。参见上面的衰减计算。 |
decay_rate | 标量float32 或float64 Tensor Python数。衰减率。 |
staircase | 布尔值。如果True 以离散间隔衰减学习率 |
name | 串。操作的可选名称。默认为'ExponentialDecay'。 |
return | |
---|---|
Tensor 与类型相同 的标量。学习率下降。 learning_rate |
Raises
ValueError | 如果未提供。 global_step |