Tensorflow函数——tf.variable_scope()
tf.variable_scope(name_or_scope,default_name=None,values=None,initializer=None,regularizer=None,caching_device=None,partitioner=None,custom_getter=None,reuse=None,dtype=None)
返回一个用于定义创建variable(层)的op的上下文管理器。
该上下文管理器验证(可选)值来自同一图形,确保图形是默认图形,并推送名称范围和variable范围。
如果name_or_scope不为None,则按原样使用。 如果范围为None,则使用default_name。 在这种情况下,如果以前在同一个范围内使用了相同的名称,那么它将会被唯一的附加到_N。
可变范围允许创建新的variable并分享已创建的variable,同时提供检查,不会意外创建或共享。 有关详细信息,请参阅可变范围如何操作,这里我们仅提供几个基本示例。
如何创建新variable的简单示例:
with tf.variable_scope("foo"):with tf.variable_scope("bar"):v = tf.get_variable("v", [1])assert v.name == "foo/bar/v:0"
- 1
- 2
- 3
- 4
共享variable的基本示例:
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
- 1
- 2
- 3
- 4
- 5
通过捕获范围并设置重用来共享variable:
with tf.variable_scope("foo") as scope:v = tf.get_variable("v", [1])scope.reuse_variables()v1 = tf.get_variable("v", [1])
assert v1 == v
- 1
- 2
- 3
- 4
- 5
为了防止意外共享variable,当在非重用范围内获取现有variable时,我们引发异常。
with tf.variable_scope("foo"):v = tf.get_variable("v", [1])v1 = tf.get_variable("v", [1])# Raises ValueError("... v already exists ...").
- 1
- 2
- 3
- 4
同样,当尝试获取在重用模式下不存在的variable时,我们引发异常。
with tf.variable_scope("foo", reuse=True):v = tf.get_variable("v", [1])# Raises ValueError("... v does not exists ...").
- 1
- 2
- 3
请注意,重用标志是继承的:如果我们打开一个重用的范围,那么它的所有子范围也会变得重用。
ARGS:
name_or_scope:string或VariableScope:要打开的范围。
default_name:如果name_or_scope参数为None,则将使用默认名称,此名称将被唯一。 如果提供了name_or_scope,它将不会被使用,因此它不是必需的,可以是None。
值:传递给op函数的Tensor参数列表。
初始化器:此范围内的变量的默认初始化程序。
regularizer:此范围内的变量的默认正则符。
caching_device:此范围内的变量的默认缓存设备。
partitioner:此范围内变量的默认分区。
custom_getter:此范围内变量的默认定制getter。
重用:True或None 如果是,我们进入该范围以及所有子范围的重用模式; 如果没有,我们只是继承父范围重用。
dtype:在此范围中创建的变量类型(默认为传递范围中的类型,或从父范围继承)
Tensorflow函数——tf.variable_scope()相关推荐
- tensorflow函数-tf.assign()
下面记录一个很简单的tensorflow代码,用来理解tensorflow运行机制 代码中有详细注释,大家可以在运行一下,为什么会是1,2,3这个结果 #-*-coding:UTF-8-*-impor ...
- tensorflow函数 tf.nn.xw_plus_b
tf.nn.xw_plus_b((x, weights) + biases.) 相当于matmul(x, weights) + biases.
- 【TensorFlow】TensorFlow函数精讲之tf.get_variable()和tf.get_variable_scope()
目录 1.tf.get_variable() 2.tf.variable_scope() 3.tf.variable_scope() 函数嵌套 1.tf.get_variable() tf.get_v ...
- 30天从入门到精通TensorFlow1.x 第三天,tf.variable_scope()共享或重用变量
tf.variable_scope()共享或重用变量 文章目录 一.接前一天 二.`tf.variable_scope()`共享或重用变量 1. 背景 2. 目的 3. `tf.variable_sc ...
- TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
scope 命名方法 对于一个复杂的 tensorflow 模型会有很多个变量, tf.variable_scope() :提供了简单的命名空间技术以避免冲突: tf.get_variable():从 ...
- 详解tf.variable_scope函数
原创 https://blog.csdn.net/qq_41058594/article/details/85165025 在学习Tensorflow进阶实例这本书时候出现了tf.variable_s ...
- tensorflow 变量及命名空间 tf.Variable() vs tf.get_variable() tf.name_scope() vs tf.variable_scope()
tf.Variable() vs tf.get_variable() tf.name_scope() vs tf.variable_scope() 1. 基础功能 1.1 tf.Variable() ...
- Tensorflow:tf.contrib.rnn.DropoutWrapper函数(谷歌已经为Dropout申请了专利!)、MultiRNNCell函数的解读与理解
Tensorflow:tf.contrib.rnn.DropoutWrapper函数(谷歌已经为Dropout申请了专利!).MultiRNNCell函数的解读与理解 目录 1.tf.contrib. ...
- 【TensorFlow】tf.nn.softmax_cross_entropy_with_logits 函数:求交叉熵损失
[TensorFlow]tf.nn.softmax_cross_entropy_with_logits的用法_xf__mao的博客-CSDN博客 https://blog.csdn.net/mao_x ...
最新文章
- 快手基于 RocketMQ 的在线消息系统建设实践
- 二叉搜索树的第 k 大节点(递归,反中序遍历 + 提前返回)
- 05 Python - Python运行
- Leet Code OJ 226. Invert Binary Tree [Difficulty: Easy]
- 如何分析 StackOverflow 异常 ?
- 轮番滑动PHP,touch事件之滑动判断(左右上下方向)
- T-SQL:毕业生出门需知系列(七)
- 修改Visual Studio中“添加新项”时默认添加的命名空间
- 5G 芯片的“春秋五霸”
- 使用xorm工具,根据数据库自动生成 go 代码
- vs2010创建动态库(亲测可行)
- 全新版本的SoundSource for Mac 优质的音频控制软件
- VC9、VC11、VC14、VC15是啥?
- OSChina 周六乱弹 ——程序员想让对象一辈子跟你的秘籍
- STC8单片机的低功耗详解
- 宾馆客房管理系统的设计与实现
- Perl读取文件信息
- iOS UDID与UUID
- struts教程笔记5
- echarts-wordcloud 热词云使用