tensflow学习小知识tf.train.exponential_decay

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)
 

如果参数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.
learning_step = (
    tf.compat.v1.train.GradientDescentOptimizer(learning_rate)
    .minimize(...my loss..., global_step=global_step)
)
 

 

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

 

return

Tensor与类型相同 的标量。学习率下降。 learning_rate

Raises

ValueError如果未提供。 global_step

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值