tf.Variable
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))
tf.Variable的更多相关文章
- tf.variable和tf.get_Variable以及tf.name_scope和tf.variable_scope的区别
在训练深度网络时,为了减少需要训练参数的个数(比如具有simase结构的LSTM模型).或是多机多卡并行化训练大数据大模型(比如数据并行化)等情况时,往往需要共享变量.另外一方面是当一个深度学习模型变 ...
- tensorflow共享变量 the difference between tf.Variable() and get_variable()
一般这样用tf.get_variable(): v = tf.get_variable(name, shape, dtype, initializer) 下面内容来源于 http://blog.csd ...
- TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
https://blog.csdn.net/lanchunhui/article/details/61712830 https://www.cnblogs.com/silence-tommy/p/70 ...
- TF.VARIABLE、TF.GET_VARIABLE、TF.VARIABLE_SCOPE以及TF.NAME_SCOPE关系
1. tf.Variable与tf.get_variable tensorflow提供了通过变量名称来创建或者获取一个变量的机制.通过这个机制,在不同的函数中可以直接通过变量的名字来使用变量,而不需要 ...
- tf.Variable() 与tf.get_variable()的区别
每次调用 tf.Variable() 都会产生一个新的变量,变量名称是一个可选参数,运行命名相同,如果命名冲突会根据命名先后对名字进行处理, tf.get_variable()的变量名称是必填参数,t ...
- 理解 tf.Variable、tf.get_variable以及范围命名方法tf.variable_scope、tf.name_scope
tensorflow提供了通过变量名称来创建或者获取一个变量的机制.通过这个机制,在不同的函数中可以直接通过变量的名字来使用变量,而不需要将变量通过参数的形式到处传递. 1. tf.Variable( ...
- tf.Variable和tensor的区别(转)
刷课过程中思考到Variable和Tensor之间的区别,尝试发现在如下代码中: a = tf.Variable(tf.ones(1)) b = tf.add(a,tf.ones(1)) 1 2 a是 ...
- 彻底弄懂tf.Variable、tf.get_variable、tf.variable_scope以及tf.name_scope异同
https://blog.csdn.net/qq_22522663/article/details/78729029 1. tf.Variable与tf.get_variabletensorflow提 ...
- TensorFlow函数(二)tf.get_variable() 和 tf.Variable()
tf.Variable(<initial - value>,name=<optional - name>) 此函数用于定义图变量.生成一个初始值为initial - value ...
随机推荐
- 收集一些常用Javascripot
获取一组单选框当前选择值: $("input[name='radGende']:checked").val();
- 解决servlet-api包冲突问题(maven)
问题描述:本人的项目是用Maven管理,而且用到了servlet3.0的技术,但是项目中用到servlet3.0的地方,总提示找不到类中的方法.很奇怪,在网上找到好多解决办法,综合一下终于解决了.现将 ...
- 解决『Manifest merger failed with multiple errors, see 』
Error:Execution failed for task ':app:processDebugManifest'.> Manifest merger failed with multipl ...
- golang学习笔记 --switch
switch的例子: switch coinflip() { case "heads": heads++ case "tails": tails++ defau ...
- MongoDB学习笔记(4)--collection
MongoDB 创建集合 本章节我们为大家介绍如何使用 MongoDB 来创建集合. MongoDB 中使用 createCollection() 方法来创建集合. 语法格式: db.createCo ...
- Aborted connection 1055898 to db: 'xxx' user: 'yyy' host: 'xxx.xxx.xxx.xxx' (Got timeout reading communication packets)
mysql错误日志中,发现大量以下类似信息:(mysql 5.7.18) [Note] Aborted connection 1055898 to db: 'xxx' user: 'yyy' host ...
- vc2010 属性值无效 灾难性故障 解决方法
原文链接: http://blog.csdn.net/enterlly/article/details/8739281 说明: 我遇到这个问题是这样的,在为某个类添加消息时出现的.因为该类不在此工程的 ...
- json解析为泛型对象
一.方法 public <T> T jsonToObjByType(String str, Type type) { try { if (isValidJson(str)) { retur ...
- U811.1接口EAI系列之五--材料出库--VB语言
主要业务有:09其他出库单 11:材料出库单 32:销售出库单 主要业务代码: '材料出库生成XML Public Function xml_storeout(ds_head As MSHFlexGr ...
- PHP规范PSR0和PSR4的理解
一.PSR0简介 下文描述了若要使用一个通用的自动加载器(autoloader),你所需要遵守的规范: 一个完全标准的命名空间(namespace)和类(class)的结构是这样的:\<Vend ...