#!/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))

最新文章

  1. TCP(传输控制协议)和三次握手和四次断开
  2. PHP之MVC学习
  3. NGUI之Slider,最简单的方法做进度条。
  4. Apache Spark源码走读之23 -- Spark MLLib中拟牛顿法L-BFGS的源码实现
  5. Java 集合系列09之 Map架构
  6. netsh修改IP及DNS
  7. dede上怎么让所有链接在新窗口打开
  8. Spark1.2新特性概述
  9. 将json格式日期(毫秒数)转成日常日期格式和日常格式时间对比
  10. aforge通过角点匹配图片相似度
  11. html5 拖拽文件到页面实现上传
  12. 数据结构之合并链表STL
  13. Python网络爬虫精要
  14. [转]CDH QuickStart VM基本使用
  15. loj#2049. 「HNOI2016」网络(set 树剖 暴力)
  16. mysql 提示表损坏处理方法
  17. 关于Git安装和操作中可能碰到的问题
  18. docker常用命令记录
  19. C/S权限系统(一)
  20. java 数组(二)

热门文章

  1. 照着官网来安装openstack pike之创建并启动instance
  2. git推送到github报错:error: The requested URL returned error: 403 Forbidden while accessing https://github.com
  3. 20145333 《Java程序设计》第二次实验报告
  4. mongodb入门很简单(2)
  5. IE兼容性视图,新增元素导致白页面
  6. 混合开发的大趋势之一React Native手势行为那些事
  7. prometheus statsd 监控
  8. Spring boot 外部资源配置
  9. javascript闭包和立即执行函数的作用
  10. 【三小时学会Kubernetes!(二) 】Kubernetes 简介及Pod实践