在训练神经网络的过程中,合理的设置学习率是一个非常重要的事情。对于训练一开始的时候,设置一个大的学习率,可以快速进行迭代,在训练后期,设置小的学习率有利于模型收敛和稳定性。
tf.train.exponential_decay(learing_rate, global_step, decay_steps, decay_rate, staircase=False)
转换方程:
实例:
import tensorflow as tf
import matplotlib.pyplot as plt
start_learning_rate = 0.1
decay_rate = 0.96
decay_step = 100
global_steps = 3000
_GLOBAL = tf.Variable(tf.constant(0))
S = tf.train.exponential_decay(start_learning_rate, _GLOBAL, decay_step, decay_rate, staircase=True)
NS = tf.train.exponential_decay(start_learning_rate, _GLOBAL, decay_step, decay_rate, staircase=False)
S_learning_rate = []
NS_learning_rate = []
with tf.Session() as sess:
for i in range(global_steps):
print(i, ' is training...')
S_learning_rate.append(sess.run(S, feed_dict={_GLOBAL: i}))
NS_learning_rate.append(sess.run(NS, feed_dict={_GLOBAL: i}))
plt.figure(1)
l1, = plt.plot(range(global_steps), S_learning_rate, 'r-')
l2, = plt.plot(range(global_steps), NS_learning_rate, 'b-')
plt.legend(handles=[l1, l2, ], labels=['staircase', 'no-staircase'], loc='best')
plt.show()
该实例表示训练过程总共迭代3000次,每经过100次,就会对学习率衰减为原来的0.96。
参考链接:
1.https://www.tensorflow.org/api_docs/python/tf/train/exponential_decay
2.https://blog.csdn.net/UESTC_C2_403/article/details/72213286