對學習率應用多項式衰減。
用法
tf.compat.v1.train.polynomial_decay(
learning_rate, global_step, decay_steps, end_learning_rate=0.0001, power=1.0,
cycle=False, name=None
)
參數
-
learning_rate
標量float32
或float64
Tensor
或 Python 編號。初始學習率。 -
global_step
標量int32
或int64
Tensor
或 Python 編號。用於衰減計算的全局步驟。不得為負。 -
decay_steps
標量int32
或int64
Tensor
或 Python 編號。必須是積極的。請參閱上麵的衰減計算。 -
end_learning_rate
標量float32
或float64
Tensor
或 Python 編號。最小的最終學習率。 -
power
標量float32
或float64
Tensor
或 Python 編號。多項式的冪。默認為線性,1.0。 -
cycle
一個布爾值,它是否應該循環超過decay_steps。 -
name
String 。操作的可選名稱。默認為'PolynomialDecay'。
返回
-
與
learning_rate
類型相同的標量Tensor
。衰減的學習率。
拋出
-
ValueError
如果未提供global_step
。
通常觀察到,單調遞減的學習率(其變化程度經過精心選擇)會產生更好的模型。此函數將多項式衰減函數應用於提供的初始 learning_rate
以達到給定 decay_steps
中的 end_learning_rate
。
它需要一個global_step
值來計算衰減的學習率。您可以隻傳遞一個 TensorFlow 變量,該變量在每個訓練步驟中遞增。
該函數返回衰減的學習率。它被計算為:
global_step = min(global_step, decay_steps)
decayed_learning_rate = (learning_rate - end_learning_rate) *
(1 - global_step / decay_steps) ^ (power) +
end_learning_rate
如果 cycle
為 True 則使用 decay_steps
的倍數,第一個大於 global_steps
。
decay_steps = decay_steps * ceil(global_step / decay_steps)
decayed_learning_rate = (learning_rate - end_learning_rate) *
(1 - global_step / decay_steps) ^ (power) +
end_learning_rate
示例:使用 sqrt 以 10000 步從 0.1 衰減到 0.01(即 power=0.5):
...
global_step = tf.Variable(0, trainable=False)
starter_learning_rate = 0.1
end_learning_rate = 0.01
decay_steps = 10000
learning_rate = tf.compat.v1.train.polynomial_decay(starter_learning_rate,
global_step,
decay_steps, end_learning_rate,
power=0.5)
# 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)
)
eager模式兼容性
當啟用即刻執行時,此函數返回一個函數,該函數又返回衰減的學習率張量。這對於在優化器函數的不同調用中更改學習率值很有用。
相關用法
- Python tf.compat.v1.train.piecewise_constant用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.get_or_create_global_step用法及代碼示例
- Python tf.compat.v1.train.cosine_decay_restarts用法及代碼示例
- Python tf.compat.v1.train.Optimizer用法及代碼示例
- Python tf.compat.v1.train.AdagradOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.init_from_checkpoint用法及代碼示例
- Python tf.compat.v1.train.Checkpoint用法及代碼示例
- Python tf.compat.v1.train.Supervisor.managed_session用法及代碼示例
- Python tf.compat.v1.train.Checkpoint.restore用法及代碼示例
- Python tf.compat.v1.train.global_step用法及代碼示例
- Python tf.compat.v1.train.MonitoredSession.run_step_fn用法及代碼示例
- Python tf.compat.v1.train.RMSPropOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.exponential_decay用法及代碼示例
- Python tf.compat.v1.train.natural_exp_decay用法及代碼示例
- Python tf.compat.v1.train.MomentumOptimizer用法及代碼示例
- Python tf.compat.v1.train.RMSPropOptimizer用法及代碼示例
- Python tf.compat.v1.train.get_global_step用法及代碼示例
- Python tf.compat.v1.train.GradientDescentOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.linear_cosine_decay用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.train.polynomial_decay。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。