#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import tensorflow as tf
my_var=tf.Variable(0.)
step=tf.Variable(0,trainable=False)
ema=tf.train.ExponentialMovingAverage(0.99,step)
maintain_average_op=ema.apply([my_var])

with tf.Session() as sess:
    init_op=tf.global_variables_initializer()
    sess.run(init_op)
    decay=0.99
    #影子变量值变化
    for i in range(1,6):
        print sess.run([my_var,ema.average(my_var)])
        sess.run(my_var.assign_add(i))
        sess.run(maintain_average_op)
        print sess.run([my_var,ema.average(my_var)])
        print "==="

    print "----------------"
    #num_updates即step变化
    sess.run(my_var.assign(5.))
    for i in range(1,20,3):
        print sess.run([my_var,ema.average(my_var)])
        sess.run(step.assign_add(i))
        sess.run(maintain_average_op)
        print sess.run([my_var,ema.average(my_var)])
        print "===" 

滑动平均模型

shadow_variable= decay * shadow_variable + (1 - decay) * variable

Reasonable values for decay are close to 1.0, typically in themultiple-nines range: 0.999, 0.9999, etc.

The apply() methodadds shadow copies of trained variables and add ops that maintain a movingaverage of the trained variables in their shadow copies. It is used whenbuilding the training model.

The optional num_updates parameter allows one to tweak thedecay rate dynamically. It is typical to pass the count of training steps,usually kept in a variable that is incremented at each step, in which case thedecay rate is lower at the start of training. This makes moving averages movefaster. If passed, the actual decay rate used is:

min(decay, (1 +num_updates) / (10 + num_updates))

TF随笔-11的更多相关文章

  1. TF随笔-4

    >>> import tensorflow as tf>>> a=tf.constant([[1,2],[3,4]])>>> b=tf.const ...

  2. TF随笔-13

    import tensorflow as tf a=tf.constant(5) b=tf.constant(3) res1=tf.divide(a,b) res2=tf.div(a,b) with ...

  3. TF随笔-10

    #!/usr/bin/env python# -*- coding: utf-8 -*-import tensorflow as tf x = tf.constant(2)y = tf.constan ...

  4. TF随笔-9

    计算累加 #!/usr/bin/env python2 # -*- coding: utf-8 -*-"""Created on Mon Jul 24 08:25:41 ...

  5. TF随笔-8

    #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Jul 10 09:35:04 201 ...

  6. TF随笔-7

    求平均值的函数 reduce_mean axis为1表示求行 axis为0表示求列 >>> xxx=tf.constant([[1., 10.],[3.,30.]])>> ...

  7. tf随笔-6

    import tensorflow as tfx=tf.constant([-0.2,0.5,43.98,-23.1,26.58])y=tf.clip_by_value(x,1e-10,1.0)ses ...

  8. tf随笔-5

    # -*- coding: utf-8 -*-import tensorflow as tfw1=tf.Variable(tf.random_normal([2,6],stddev=1))w2=tf. ...

  9. TF随笔-3

    >>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>& ...

随机推荐

  1. saltstack之keepalived的安装配置

    使用saltstack编译安装keepalived: 创建相应的目录,并在目录下创建相应的sls配置文件 [root@node1 ~]# mkdir /srv/salt/prod/keepalived ...

  2. PostgreSQL 递归查询 (转)

    数据库中的数据存在父子关系(单继承,每一条记录只有一个父亲).  如果要查询一条记录以及他的所有子记录,或者要查询一条记录以及他的所有父记录.那么递归查询就再合适不过了.可以简化复杂的SQL语句 现在 ...

  3. 快用Visual Studio(一)- 打开文件

    在命令行中使用Visual Studio code打开文件: 打开Visual Studio code: CMD + SHIFT + P打开控制面板: 键入"shell command&qu ...

  4. 《面向对象的JavaScript》读书笔记

    发现了2004年出版的一本好书,用两天快速刷了一遍,草草整理了一下笔记,在此备忘. 类:对象的设计蓝图或制作配方. 对象 === 实例 :老鹰是鸟类的一个实例 基于相同的类创建出许多不同的对象,类更多 ...

  5. bzoj 3450: Tyvj1952 Easy

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 411  Solved: 309[Submit][Status][Discuss] Descriptio ...

  6. CentOS 7配置静态IP地址

    [root@centos1 ~]# ifconfig -bash: ifconfig: command not found 首先,习惯性的输入echo $PATH(查看当前PATH环境变量,跟DOS的 ...

  7. CentOS安装wkhtmltopdf及解决中文支持问题

    安装wkhtmltopdf,先下载  wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm yum install -y wkhtmltox-0.12.2.1_linu ...

  8. 防止xss(脚本攻击)的方法之过滤器

    一  什么是脚本注入 概念我就不说了 直接百度一份 XSS是一种经常出现在web应用中的计算机安全漏洞,它允许恶意web用户将代码植入到提供给其它用户使用的页面中.比如这些代码包括HTML代码和客户端 ...

  9. 将应用注册为Linux的服务

    主流的Linux大多使用init.d或systemd来注册服务.下面以centos6.6演示init.d注册服务:以centos7.1演示systemd注册服务. 1. 基于Linux的init.d部 ...

  10. “Too many open files” 小记

    pycharm远程链接centos7开发过程中突然遇到“Too many open files”. 几点记录: 1. 命令:ulimit -n 查看系统配置,其中的 表示每个进程最多能打开8192个文 ...