tf.get_variable()
来源:互联网 发布:直播系统源码 php 编辑:程序博客网 时间:2024/05/22 01:53
tf.get_variable()通常和tf.variable_scope()一起使用,可用来共享变量
- tf.get_variable(name, shape, initializer): 通过所给的名字创建或是返回一个变量.
- tf.variable_scope(): 通过 tf.get_variable()为变量名指定命名空间.
函数tf.get_variable() 用来获取或创建一个变量,不同于tf.Variable那样直接传值,tf.get_variable()用initializer来创建变量。一个initializer 就是一个函数,创建一个形状是shape的张量。TensorFlow中使用的initializer有以下几种 :
- tf.constant_initializer(value) 用value初始化所有的值。initializes everything to the provided value,
- tf.random_uniform_initializer(a, b) 从a到b均匀初始化,
- tf.random_normal_initializer(mean, stddev) 用所给平均值和标准差初始化均匀分布
v = tf.get_variable(name, shape, dtype, initializer)
情况1:当tf.get_variable_scope().reuse == False
时,作用域就是为创建新变量所设置的。
这种情况下,v将通过tf.Variable所提供的形状和数据类型来重新创建。创建变量的全称将会由当前变量作用域名+所提供的名字所组成,并且还会检查来确保没有任何变量使用这个全称。如果这个全称已经有一个变量使用了,那么方法将会抛出ValueError错误。如果一个变量被创建,用initializer(shape)进行初始化。比如:
with tf.variable_scope("foo"): v = tf.get_variable("v", [1])assert v.name == "foo/v:0"
情况2:当tf.get_variable_scope().reuse == True
时,作用域是为重用变量所设置的。
这种情况下,调用就会搜索一个已经存在的变量,变量的全称和当前变量的作用域名+所提供的名字是否相等。如果不存在相应的变量,就会抛出ValueError 错误。如果变量找到了,就返回这个变量。如下:
with tf.variable_scope("foo"): v = tf.get_variable("v", [1])with tf.variable_scope("foo", reuse=True): v1 = tf.get_variable("v", [1])assert v1 == v
0 0
- tf.get_variable()
- tf.get_variable 和tf.variable_scope
- tf.get_variable 和tf.variable_scope
- tf.get_variable 和tf.variable_scope
- tf.get_variable tf.variable_scope tf.name_scope
- tf.get_variable函数的使用
- tf.get_variable函数的使用
- tf.Variable()与tf.get_variable()与不同之处
- tf.Variable()与tf.get_variable()对比
- tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- #tensorflow学习笔记#理解tf.get_variable
- TensorFlow学习--tf.get_variable使用
- tensorflow共享变量, tf.get_variable() 和 tf.Varibele()的区别
- Tensorflow中tf.get_variable和tf.variable_scope的使用
- tf.Variable()和tf.get_variable()的使用方法和相同点
- 【tensorflow 学习】tf.get_variable()和tf.Variable()的区别
- TensorFlow tf.Variable()与tf.get_variable()的简单介绍
- 21. Merge Two Sorted Lists
- maven(15),快照与发布,RELEASE与SNAPSHOT
- 第五周作业1(LeetCode50)
- JavaScript单线程 & setTimeout定时器
- 数据结构实验之链表五:单链表的拆分
- tf.get_variable()
- vscode常用插件
- 笔记31-35
- openfire如何整合不同的用户系统
- activiti 设置流程变量
- R语言基础
- Java-----String.getBytes()
- Android xUtils3.0 数据库操作出错
- spark 日记一