Tesorflow学习笔记(1)
2016-05-18 10:56
281 查看
参考网址:http://www.turnote.com/doc/SOURCE/api_docs/python/state_ops.html
参考网址:http://www.turnote.com/how_tos/variables/index.html
Variable变量
(1)定义:A
variable maintains state in the graph across calls to
run()
(2)使用方法:
import
tensorflow as tf
#create a
variable
w =
tf.Variable(,
)
(3)变量的初始化
with
tf.Session() as sess
init_op =
tf.initialize_all_variables()#初始化所有的变量
sess.run(init_op)#then you can run the ops that use all the
variables
with
tf.Session as sess
sess.run(w.initializer)#then you can run the ops
that use variable 'w'
(4)使用一个变量初始化另一个变量
w = tf.Variable(tf.random_normal([10,20],stddev
= 0.35),name = 'weight')
w_2 = tf.Variable(w.initialized_value(),name =
'w_2')
tf.train.Saver()类
tf.train.Saver()创建一个saver对象来管理模型中的所有变量
第二个用处:恢复变量
用同一个
恢复变量时变量的个数和名称必须与保存时相同,否则会报错!!
[/code]
Saver()如果什么参数都不加,则会保存所有的变量值,如果想只保存一部分变量名,可以用如下方法:
[/code]
参考网址:http://www.turnote.com/how_tos/variables/index.html
Variable变量
(1)定义:A
variable maintains state in the graph across calls to
run()
(2)使用方法:
import
tensorflow as tf
#create a
variable
w =
tf.Variable(,
)
(3)变量的初始化
with
tf.Session() as sess
init_op =
tf.initialize_all_variables()#初始化所有的变量
sess.run(init_op)#then you can run the ops that use all the
variables
with
tf.Session as sess
sess.run(w.initializer)#then you can run the ops
that use variable 'w'
(4)使用一个变量初始化另一个变量
w = tf.Variable(tf.random_normal([10,20],stddev
= 0.35),name = 'weight')
w_2 = tf.Variable(w.initialized_value(),name =
'w_2')
tf.train.Saver()类
tf.train.Saver()创建一个saver对象来管理模型中的所有变量
第二个用处:恢复变量
用同一个
Saver对象来恢复变量。注意,当你从文件中恢复变量时,不需要事先对它们做初始化。
恢复变量时变量的个数和名称必须与保存时相同,否则会报错!!
[code]# Create some variables. v1 = tf.Variable(..., name="v1") v2 = tf.Variable(..., name="v2") ... # Add ops to save and restore all the variables. saver = tf.train.Saver() # Later, launch the model, use the saver to restore variables from disk, and # do some work with the model. with tf.Session() as sess: # Restore variables from disk. saver.restore(sess, "/tmp/model.ckpt") print "Model restored." # Do some work with the model
[/code]
Saver()如果什么参数都不加,则会保存所有的变量值,如果想只保存一部分变量名,可以用如下方法:
[code]v1 = tf.Variable(..., name='v1') v2 = tf.Variable(..., name='v2') # Pass the variables as a dict: saver = tf.train.Saver({'v1': v1, 'v2': v2}) # Or pass them as a list. saver = tf.train.Saver([v1, v2]) # Passing a list is equivalent to passing a dict with the variable op names # as keys: saver = tf.train.Saver({v.op.name: v for v in [v1, v2]})
[/code]
相关文章推荐
- tensorflow常用函数记录
- java后台获取request,response
- java中的matches()方法
- 几种开发者常见的开源软件协议的分析与介绍
- Java多线程中提到的原子性和可见性、有序性
- 重写、覆盖、重载、多态的区别的分析
- jquery param 数组 带有 %5B%5D [] 问题
- 版本更新2
- 基于WEB的企业用能信息在线填报系统设计
- Spring中切面的<aop:advisor pointcut="execution参数解析
- HTTP请求错误大全
- birt 的library进行公用数据库连接设置
- 【ionic】项目应用requireJs前端模块化
- svg线条动画基础
- HTML5 input date 移动端 IOS 不支持问题
- 瀑布流照片实现
- Java线程:概念与原理
- #pragma once 和 #ifndef 的区别
- 343. Integer Break
- Zedboard移植QT