1. 程式人生 > >TensorFlow 中的 tf.train.exponential_decay() 指數衰減法

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.然後通過迭代逐步減小學習率(目的:為使模型在訓練後期更加穩定);