日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow之tf.train.exponential_decay()指数衰减法

發布時間:2023/12/18 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow之tf.train.exponential_decay()指数衰减法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

exponential_decay(learning_rate,? global_steps, decay_steps, decay_rate, staircase=False, name=None)

使用方式:

tf.tf.train.exponential_decay()

例子:

tf.train.exponential_decay(self.config.e_lr, self.e_global_steps,self.config.decay_steps, self.config.decay_rate, staircase=True)

在 Tensorflow 中,exponential_decay()是應用于學習率的指數衰減函數(實現指數衰減學習率)。

在訓練模型時,通常建議隨著訓練的進行逐步降低學習率。該函數需要`global_step`值來計算衰減的學習速率。

該函數返回衰減后的學習率。該函數的計算方程式如下

參數:

  • learning_rate - 初始學習率
  • global_step -?用于衰減計算的全局步驟。 一定不為負數。喂入一次 BACTH_SIZE 計為一次 global_step
  • decay_steps - 衰減速度,一定不能為負數,每間隔decay_steps次更新一次learning_rate值
  • decay_rate - 衰減系數,衰減速率,其具體意義參看函數計算方程(對應α^t中的α)。
  • staircase - 若 ‘ True ’ ,則學習率衰減呈 ‘ 離散間隔 ’ (discrete intervals),具體地講,`global_step / decay_steps`是整數除法,衰減學習率( the decayed learning rate )遵循階梯函數;若為 ’ False ‘ ,則更新學習率的值是一個連續的過程,每步都會更新學習率。

返回值:

  • 與初始學習率 ‘ learning_rate ’ 相同的標量 ’ Tensor ‘ 。

?優點:

  • 訓練伊始可以使用較大學習率,以快速得到比較優的解。
  • 后期通過逐步衰減后的學習率進行迭代訓練,以使模型在訓練后期更加穩定。?

示例代碼:

import tensorflow as tf
import matplotlib.pyplot as plt

learning_rate = 0.1
decay_rate = 0.96
global_steps = 1000
decay_steps = 100

global_step = tf.Variable(0, trainable = Fasle)
c = tf.train.exponential_decay(learning_rate, global_step, decay_steps, decay_rate, staircase=True)
d = tf.train.exponential_decay(learning_rate, global_step, decay_steps, decay_rate, staircase=False)

T_C = []
F_D = []

with tf.Session() as sess:
for i in range(global_steps):
T_c = sess.run(c, feed_dict={global_step: i})
T_C.append(T_c)
F_d = sess.run(d, feed_dict={global_step: i})
F_D.append(F_d)

plt.figure(1)
plt.plot(range(global_steps), F_D, 'r-')
plt.plot(range(global_steps), T_C, 'b-')

plt.show()

實操:

運行結果:

備注:

(1)

臺階形狀的藍色線是?staircase =?True

線條形狀的紅色線是?staircase = Fasle

(2)

初始學習率 learning_rate 為0.1,總訓練次數 global_setps 為 1000 次;staircase=True時,每隔?decay_steps = 100 次更新一次 學習率 learning_rate,而staircase=True時,每一步均會更新一次學習率 learning_rate ,

(3)

訓練過程中,decay_rate的數值保持步不變。

?

參考文獻:https://www.cnblogs.com/gengyi/p/9898960.html

轉載于:https://www.cnblogs.com/happystudyeveryday/p/11144433.html

總結

以上是生活随笔為你收集整理的tensorflow之tf.train.exponential_decay()指数衰减法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。