指数衰减

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

learning_rate = 0.001
decay_rate = 0.001#这个太小了
global_steps = 60
decay_steps = 5
#staircase=False, 默认为False,为True则不衰减
global_step = tf.Variable(0)
lr1 = tf.exponential_decay(
    learning_rate = learning_rate,
    global_step = global_step,
    decay_steps = decay_steps,
    decay_rate = decay_rate,
    staircase = True
    #tf.train.exponential_decay还有一个参数是staircase,默认为False,如果是False,学习率会平滑地衰减,而非每迭代1000轮才衰减一次,如果为True,则会每迭代1000次才衰减一次,这种称为阶梯函数。
)
lr2 = tf.exponential_decay(
    learning_rate = learning_rate,
    global_step = global_step,
    decay_steps = decay_steps,
    decay_rate = decay_rate,
    staircase = False
)

LR1 = []
LR2 = []
with tf.Session() as sess:
    for i in range(global_steps):
        LR1.append(sess.run(lr1, feed_dict = {global_step: i}))
        LR2.append(sess.run(lr2, feed_dict = {global_step: i}))

plt.figure(1)
plt.plot(range(global_steps), LR1, 'r-')
plt.plot(range(global_steps), LR2, 'b-')
plt.show()
decayed_learning_rate = 
learning_rate * decay_rate ^(global_step / decay_ steps) 
红色表示staircase=True,绿色表示staircase=False。

在这里插入图片描述

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

learning_rate = 0.001
decay_rate = 0.001
global_steps = 60
decay_steps = 60

global_step = tf.Variable(0)
lr1 = tf.exponential_decay(
    learning_rate = learning_rate,
    global_step = global_step,
    decay_steps = decay_steps,
    decay_rate = decay_rate,
    staircase = True
)
lr2 = tf.exponential_decay(
    learning_rate = learning_rate,
    global_step = global_step,
    decay_steps = decay_steps,
    decay_rate = decay_rate,
    staircase = False
)

LR1 = []
LR2 = []
with tf.Session() as sess:
    for i in range(global_steps):
        LR1.append(sess.run(lr1, feed_dict = {global_step: i}))
        LR2.append(sess.run(lr2, feed_dict = {global_step: i}))

plt.figure(1)
plt.plot(range(global_steps), LR1, 'r-')
plt.plot(range(global_steps), LR2, 'b-')
plt.show()

在这里插入图片描述

问题:tf.train.exponential_decay在tf2.0里面去掉这个API了,但是还不知道代替的是啥

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值