Tensorflow函数——tf.variable_scope()
Tensorflow函数——tf.variable_scope()详解
https://blog.csdn.net/yuan0061/article/details/80576703
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
- 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
- 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
- 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
- 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
- 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:在此范围中创建的变量类型(默认为传递范围中的类型,或从父范围继承)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
返回:
可以捕获和重复使用的范围。
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css">
</div>
Tensorflow函数——tf.variable_scope()的更多相关文章
- Tensorflow函数——tf.placeholder()函数
tf.placeholder()函数 Tensorflow中的palceholder,中文翻译为占位符,什么意思呢? 在Tensoflow2.0以前,还是静态图的设计思想,整个设计理念是计算流图,在编 ...
- Tensorflow函数——tf.set_random_seed(seed)
设置图级随机seed. 依赖于随机seed的操作实际上从两个seed中获取:图级和操作级seed. 这将设置图级别的seed. 其与操作级seed的相互作用如下: 1.如果没有设置图形级别和操作see ...
- TensorFlow函数: tf.stop_gradient
停止梯度计算. 在图形中执行时,此操作按原样输出其输入张量. 在构建计算梯度的操作时,这个操作会阻止将其输入的共享考虑在内.通常情况下,梯度生成器将操作添加到图形中,通过递归查找有助于其计算的输入来计 ...
- TensorFlow函数(三)tf.variable_scope() 和 tf.name_scope()
tf.name_scope() 此函数作用是共享变量.在一个作用域scope内共享一些变量,简单来说,就是给变量名前面加个变量空间名,只限于tf.Variable()的变量 tf.variable_s ...
- tensorflow中共享变量 tf.get_variable 和命名空间 tf.variable_scope
tensorflow中有很多需要变量共享的场合,比如在多个GPU上训练网络时网络参数和训练数据就需要共享. tf通过 tf.get_variable() 可以建立或者获取一个共享的变量. tf.get ...
- Tensorflow常用的函数:tf.cast
1.tf.cast(x,dtype,name) 此函数的目的是为了将x数据,准换为dtype所表示的类型,例如tf.float32,tf.bool,tf.uint8等 example: import ...
- TensorFlow函数教程:tf.nn.dropout
tf.nn.dropout函数 tf.nn.dropout( x, keep_prob, noise_shape=None, seed=None, name=None ) 定义在:tensorflow ...
- 第三节,TensorFlow 使用CNN实现手写数字识别(卷积函数tf.nn.convd介绍)
上一节,我们已经讲解了使用全连接网络实现手写数字识别,其正确率大概能达到98%,这一节我们使用卷积神经网络来实现手写数字识别, 其准确率可以超过99%,程序主要包括以下几块内容 [1]: 导入数据,即 ...
- TensorFlow函数:tf.truncated_normal
tf.truncated_normal函数 tf.truncated_normal( shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, ...
随机推荐
- ASP.NET Core MVC 概述
https://docs.microsoft.com/zh-cn/aspnet/core/mvc/overview?view=aspnetcore-2.2 ASP.NET Core MVC 概述 20 ...
- leetcode1005
func largestSumAfterKNegations(A []int, K int) int { sort.Ints(A) var negatives int var zeros int va ...
- 文件系统(File System)
什么是文件系统,引用百科解释: 操作系统中负责管理和存储文件信息的软件机构称为文件管理系统,简称文件系统. 文件系统是操作系统核心的组成部分,没有它我们无法完成对文件的增.删.改.查等基本操作 概念 ...
- Oracle修改表或者字段的注释
转自:https://www.cnblogs.com/fx-blog/p/7132833.html 语句:comment on table 表名 is '表的注释信息'; comment on col ...
- js 深度拷贝
js 数据类型 分为2种: 基本数据类型:Undefined.Null.Boolean.Number.String 复杂数据类型:Object.Array.function 他们的区别是在内存中的存储 ...
- 机器学习进阶-图像金字塔与轮廓检测-图像金字塔-(**高斯金字塔) 1.cv2.pyrDown(对图片做向下采样) 2.cv2.pyrUp(对图片做向上采样)
1.cv2.pyrDown(src) 对图片做向下采样操作,通常也可以做模糊化处理 参数说明:src表示输入的图片 2.cv2.pyrUp(src) 对图片做向上采样操作 参数说明:src表示输入的 ...
- hive基础操作
hive --version 查看hive的版本 hive -S -e "set" | grep auto ##在shell下可以查找属性的状态.小技巧.
- HTML一般标签
<title>无标题文档</title> </head> <body bgcolor="#33CC33" background=" ...
- linux查询硬件信息
硬件信息查询 sudo dmidecode -t baseboard
- 应用SharedPreference保存程序的配置信息
SharedPreference: 1.用来保存应用程序的配置信息的XML文件,内部的数据形式为键值对 2.一般存在于/data/data/<包名>shared_prefs目录下 3.该对 ...