【TensorFlow】关键字global_step使用(十)
来源:互联网 发布:腾牛网软件下载 编辑:程序博客网 时间:2024/06/02 03:46
global_step经常在滑动平均,学习速率变化的时候需要用到,这个参数在
tf.train.GradientDescentOptimizer(learning_rate).minimize(loss, global_step=global_steps)里面有,系统会自动更新这个参数的值,从1开始。
请看实例:
import tensorflow as tf; import numpy as np; import matplotlib.pyplot as plt; x = tf.placeholder(tf.float32, shape=[None, 1], name='x') y = tf.placeholder(tf.float32, shape=[None, 1], name='y') w = tf.Variable(tf.constant(0.0)) global_steps = tf.Variable(0, trainable=False) learning_rate = tf.train.exponential_decay(0.1, global_steps, 10, 2, staircase=False) loss = tf.pow(w*x-y, 2) train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss, global_step=global_steps) with tf.Session() as sess: sess.run(tf.initialize_all_variables()) for i in range(10): sess.run(train_step, feed_dict={x:np.linspace(1,4,10).reshape([10,1]), y:np.linspace(1,4,10).reshape([10,1])}) print('learning_rate:{}'.format(sess.run(learning_rate))) print('global_steps:{}'.format(sess.run(global_steps)))
输出:
learning_rate:0.10717733949422836
global_steps:1
learning_rate:0.11486983299255371
global_steps:2
learning_rate:0.1231144443154335
global_steps:3
learning_rate:0.13195079565048218
global_steps:4
learning_rate:0.1414213627576828
global_steps:5
learning_rate:0.15157166123390198
global_steps:6
learning_rate:0.16245047748088837
global_steps:7
learning_rate:0.17411011457443237
global_steps:8
learning_rate:0.18660660088062286
global_steps:9
learning_rate:0.20000000298023224
global_steps:10
学习速率第一次训练开始变化,global_steps每次自动加1
阅读全文
0 0
- 【TensorFlow】关键字global_step使用(十)
- TensorFlow-关键字global_step使用
- tensorflow中的关键字global_step使用
- tensorflow中的关键字global_step使用
- tensorflow中的global_step等概念的理解
- TensorFlow中global_step的简单分析
- TensorFlow学习笔记(十)
- tensorflow学习笔记(十):sess.run()
- TensorFlow学习(十):图像预处理
- TensorFlow学习笔记(十): CIFAR-10
- tensorflow学习笔记(十):sess.run()
- C语言强化(十)求 1+2+…+n | 要求:不使用关键字
- php面向对象全攻略 (十) final static const关键字的使用
- Java学习--(十)final关键字
- C语言中的一些关键字(十)
- Lucene4.10使用教程(十):Lucene的关键字高亮
- Lucene4.10使用教程(十):Lucene的关键字高亮
- Lucene4.10使用教程(十):Lucene的关键字高亮
- 《android framework常用api源码分析》之 app应用安装流程
- 贝叶斯分类器
- 解决Android Studio 3.0 Window 环境下 搜狗等输入法卡顿、不流畅、反应慢。不提示等异常问题
- 子线程主线程循环交替执行
- 金额---元转分
- 【TensorFlow】关键字global_step使用(十)
- 自动备份远程机器的脚本
- java中比较double大小
- 主题提取 问题解决思路
- Maven搭建hadoop环境报Missing artifact jdk.tools:jdk.tools:jar:1.6
- Thinking in Java:第五章-初始化与清理
- 润乾V5web端预览报错 cell num exceeds limit 的解决方案
- 高手详解SQL性能优化十条经验
- Yii2中多表关联查询(hasOne、hasMany、join、joinwith)