1. import tensorflow as tf;  
  2. import numpy as np;  
  3. import matplotlib.pyplot as plt;  
  4.   
  5. learning_rate = 0.1  
  6. decay_rate = 0.96  
  7. global_steps = 1000  
  8. decay_steps = 100  
  9.   
  10. global_ = tf.Variable(tf.constant(0))  
  11. c = tf.train.exponential_decay(learning_rate, global_, decay_steps, decay_rate, staircase=True)  
  12. d = tf.train.exponential_decay(learning_rate, global_, decay_steps, decay_rate, staircase=False)  
  13.   
  14. T_C = []  
  15. F_D = []  
  16.   
  17. with tf.Session() as sess:  
  18.     for i in range(global_steps):  
  19.         T_c = sess.run(c,feed_dict={global_: i})  
  20.         T_C.append(T_c)  
  21.         F_d = sess.run(d,feed_dict={global_: i})  
  22.         F_D.append(F_d)  
  23.   
  24.   
  25. plt.figure(1)  
  26. plt.plot(range(global_steps), F_D, 'r-')  
  27. plt.plot(range(global_steps), T_C, 'b-')  
  28.       

  1. plt.show()  
  2. 分析:

    初始的学习速率是0.1,总的迭代次数是1000次,如果staircase=True,那就表明每decay_steps次计算学习速率变化,更新原始学习速率,如果是False,那就是每一步都更新学习速率。红色表示False,绿色表示True。


    结果:

    学习率的改变


相关文章:

  • 2022-01-21
  • 2021-12-23
  • 2021-04-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2022-03-02
  • 2021-09-21
猜你喜欢
  • 2021-05-26
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-06-27
相关资源
相似解决方案