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

使用方式为

tf.train.exponential_decay( )

在 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的数值保持步不变。

TensorFlow 中的 tf.train.exponential_decay() 指数衰减法的更多相关文章

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

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

  2. Tensorflow中的tf.argmax()函数

    转载请注明出处:http://www.cnblogs.com/willnote/p/6758953.html 官方API定义 tf.argmax(input, axis=None, name=None ...

  3. tensorflow中使用tf.variable_scope和tf.get_variable的ValueError

    ValueError: Variable conv1/weights1 already exists, disallowed. Did you mean to set reuse=True in Va ...

  4. [转载]tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定

    tf.ConfigProto()函数用在创建session的时候,用来对session进行参数配置: config = tf.ConfigProto(allow_soft_placement=True ...

  5. tensorflow中共享变量 tf.get_variable 和命名空间 tf.variable_scope

    tensorflow中有很多需要变量共享的场合,比如在多个GPU上训练网络时网络参数和训练数据就需要共享. tf通过 tf.get_variable() 可以建立或者获取一个共享的变量. tf.get ...

  6. tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定

    tf.ConfigProto()函数用在创建session的时候,用来对session进行参数配置: config = tf.ConfigProto(allow_soft_placement=True ...

  7. tf.Session()函数的参数应用(tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/dcrmg/article/details ...

  8. tensorflow中的tf.app.run()的使用

    指明函数的入口,即从哪里执行函数. 如果你的代码中的入口函数不叫main(),而是一个其他名字的函数,如test(),则你应该这样写入口tf.app.run(test()) 如果你的代码中的入口函数叫 ...

  9. tensorflow中协调器 tf.train.Coordinator 和入队线程启动器 tf.train.start_queue_runners

    TensorFlow的Session对象是支持多线程的,可以在同一个会话(Session)中创建多个线程,并行执行.在Session中的所有线程都必须能被同步终止,异常必须能被正确捕获并报告,会话终止 ...

随机推荐

  1. CodeForces 569B Inventory 货物编号

    原题: http://codeforces.com/contest/569/problem/B 题目: Inventory time limit per test1 second memory lim ...

  2. [Canvas]人物型英雄出现(前作仅为箭头)

    源码点此下载,用浏览器打开index.html观看. 代码: <!DOCTYPE html> <html lang="utf-8"> <meta ht ...

  3. SpringBoot开发详解(六)-- 异常统一管理以及AOP的使用

    https://blog.csdn.net/qq_31001665/article/details/71357825

  4. Apache Rewrite规则详解

    参考链接:http://slj.me/2009/04/apache-rewrite-regular/ 1.Rewrite规则简介 Rewirte主要的功能就是实现URL的跳转,它的正则表达式是基于Pe ...

  5. 牛客网-《剑指offer》-用两个栈实现队列

    题目:http://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6 C++ class Solution { public: vo ...

  6. LintCode: Fizz Buzz

    C++ class Solution { public: /** * param n: As description. * return: A list of strings. */ vector&l ...

  7. 转:FSMT:文件服务器从03迁移到08R2实战演练

    另外参见:http://www.canway.net/Lists/CanwayOriginalArticels/DispForm.aspx?ID=282 以前做过一个项目,是把文件服务器从03升级到0 ...

  8. 使用MAVEN打JAR,直接使用

    一.简单的方法: 首先在pom.xml里面添加: <build> <plugins> <plugin> <artifactId>maven-assemb ...

  9. web.xml关于spring的讲解

    <context-param>的作用: web.xml的配置中<context-param>配置作用 . 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件w ...

  10. http put post请求区别

    1.RESTful API REST: Representational State Transfer url 对应服务器上的一种资源,e.g. 数据,图片等,所以url 中只含有名词,通过HTTP动 ...