tf.Variable
2024-10-15 23:31:29
tf.Variable
__init__(
initial_value=None,
trainable=True,
collections=None,
validate_shape=True,
caching_device=None,
name=None,
variable_def=None,
dtype=None,
expected_shape=None,
import_scope=None
)
功能说明:
维护图在执行过程中的状态信息,例如神经网络权重值的变化。
参数列表:
参数名 | 类型 | 说明 |
---|---|---|
initial_value | 张量 | Variable 类的初始值,这个变量必须指定 shape 信息,否则后面 validate_shape 需设为 False |
trainable | Boolean | 是否把变量添加到 collection GraphKeys.TRAINABLE_VARIABLES 中(collection 是一种全局存储,不受变量名生存空间影响,一处保存,到处可取) |
collections | Graph collections | 全局存储,默认是 GraphKeys.GLOBAL_VARIABLES |
validate_shape | Boolean | 是否允许被未知维度的 initial_value 初始化 |
caching_device | string | 指明哪个 device 用来缓存变量 |
name | string | 变量名 |
dtype | dtype | 如果被设置,初始化的值就会按照这个类型初始化 |
expected_shape | TensorShape | 要是设置了,那么初始的值会是这种维度 |
示例代码:
import tensorflow as tf
initial= tf.truncated_normal(shape=[10,10],mean=0,stddev=1)
W=tf.Variable(initial)
list=[[1.,1.],[2.,2.]]
X=tf.Variable(list,dtype=tf.float32)
ini_op=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(ini_op)
print(sess.run(W[:2,:2])) op=W[:2,:2].assign(22.*tf.ones((2,2)))
print(sess.run(op))
print (W.eval()) #Usage with the default session
print ("#####################(6)#############")
print (W.dtype)
print (sess.run(W.initial_value))
print (sess.run(W.op))
print (W.shape)
print ("###################(7)###############")
print (sess.run(X))
最新文章
- MVC之Ajax.BeginForm使用详解之更新列表
- win2008使用FireDac连接ORACLE数据库问题
- 转:Linux内部的时钟处理机制全面剖析
- SQLServer 列出每个表的列和属性
- CSS抗锯齿 font-smoothing 属性介绍
- jquery 判断时间
- xss之全面剖析
- libswscale图像格式转换与放大缩小
- ural 1150. Page Numbers
- Elf 32
- 判断联网wifi
- Cup
- springboot v2.0.3版本多数据源配置
- Java基础系列-equals方法和hashCode方法
- RevDebug -- VS 调试神器,你值得拥有!
- 数据挖掘领域十大经典算法之—SVM算法(超详细附代码)
- thymeleaf:日常使用总结
- 查看linux系统CPU及内存配置
- 第三次实验计算分段函数 第四次计算分段函数和循环NEW 第五次分支+循环加强版 实验报告
- 前端框架VUE----学习vue前的准备工作
热门文章
- php安装 出现Sorry, I cannot run apxs. ***错误解决方法
- ubuntu源列表(清华,阿里,官方,选一即可)
- C语言终极面试及答案分析
- 【代码导读】Github 开源项目——wysihtml5 富编辑器(Bootstrap 风格)【一】
- C# WinForm开发系列 - 文章索引
- Html插入Flash.object.embed.swf各个参数值详解介绍[等比例缩放]
- 【MyBatis】MyBatis之分页
- Swift 多态
- 简单示例:Spring4 整合 单个Redis服务
- Mac下安装mysql8.0.11