tf.compat.v1.train.exponential_decay用法

tf.compat.v1.train.exponential_decay:将指数衰减应用于学习率。

tf.compat.v1.train.exponential_decay(
    learning_rate, global_step, decay_steps, decay_rate, staircase=False, name=None
)

训练模型时,通常建议随着训练的进行降低学习率。此函数将指数衰减函数应用于提供的初始学习率。它需要一个global_step值来计算衰减的学习率。您只需传递一个TensorFlow变量,即可在每个训练步骤中增加该变量。

该函数返回衰减的学习率。计算公式为:

decayed_learning_rate = learning_rate *
                        decay_rate ^ (global_step / decay_steps)

如果参数staircaseTrueglobal_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.
# 其中it指的是global_step
learning_step = (
    tf.compat.v1.train.GradientDescentOptimizer(learning_rate)
    .minimize(...my loss..., global_step=global_step)
)

Args

learning_rate 一个float32float64的标量Tensor或者一个Python数。初始学习率。
global_step 一个int32int64的标量Tensor或者一个Python数。全局步骤用于衰减计算。不能为负。
decay_steps 一个int32int64的标量Tensor或者一个Python数。必须是正的。参见上面的衰减计算。
decay_rate 一个float32float64的标量Tensor或者一个Python数。衰减率。
staircase 布尔值。如果True以离散间隔衰减学习率
name 字符串。操作的可选名称。默认为'ExponentialDecay'。

Returns

learning_rate类型相同的标量Tensor。衰减的学习率。 

Raises

ValueError 如果global_step未提供。 

Eager Compatibility

启用急切执行后,此函数返回一个函数,该函数又返回衰减的学习率Tensor。这对于在优化器函数的不同调用之间更改学习率值很有用。

猜你喜欢

转载自blog.csdn.net/qq_36201400/article/details/108573792
今日推荐