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()相关推荐

  1. tensorflow函数-tf.assign()

    下面记录一个很简单的tensorflow代码,用来理解tensorflow运行机制 代码中有详细注释,大家可以在运行一下,为什么会是1,2,3这个结果 #-*-coding:UTF-8-*-impor ...

  2. tensorflow函数 tf.nn.xw_plus_b

    tf.nn.xw_plus_b((x, weights) + biases.) 相当于matmul(x, weights) + biases.

  3. 【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 ...

  4. 30天从入门到精通TensorFlow1.x 第三天,tf.variable_scope()共享或重用变量

    tf.variable_scope()共享或重用变量 文章目录 一.接前一天 二.`tf.variable_scope()`共享或重用变量 1. 背景 2. 目的 3. `tf.variable_sc ...

  5. TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()

    scope 命名方法 对于一个复杂的 tensorflow 模型会有很多个变量, tf.variable_scope() :提供了简单的命名空间技术以避免冲突: tf.get_variable():从 ...

  6. 详解tf.variable_scope函数

    原创 https://blog.csdn.net/qq_41058594/article/details/85165025 在学习Tensorflow进阶实例这本书时候出现了tf.variable_s ...

  7. 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() ...

  8. Tensorflow:tf.contrib.rnn.DropoutWrapper函数(谷歌已经为Dropout申请了专利!)、MultiRNNCell函数的解读与理解

    Tensorflow:tf.contrib.rnn.DropoutWrapper函数(谷歌已经为Dropout申请了专利!).MultiRNNCell函数的解读与理解 目录 1.tf.contrib. ...

  9. 【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 ...

最新文章

  1. 快手基于 RocketMQ 的在线消息系统建设实践
  2. 二叉搜索树的第 k 大节点(递归,反中序遍历 + 提前返回)
  3. 05 Python - Python运行
  4. Leet Code OJ 226. Invert Binary Tree [Difficulty: Easy]
  5. 如何分析 StackOverflow 异常 ?
  6. 轮番滑动PHP,touch事件之滑动判断(左右上下方向)
  7. T-SQL:毕业生出门需知系列(七)
  8. 修改Visual Studio中“添加新项”时默认添加的命名空间
  9. 5G 芯片的“春秋五霸”
  10. 使用xorm工具,根据数据库自动生成 go 代码
  11. vs2010创建动态库(亲测可行)
  12. 全新版本的SoundSource for Mac 优质的音频控制软件
  13. VC9、VC11、VC14、VC15是啥?
  14. OSChina 周六乱弹 ——程序员想让对象一辈子跟你的秘籍
  15. STC8单片机的低功耗详解
  16. 宾馆客房管理系统的设计与实现
  17. Perl读取文件信息
  18. iOS UDID与UUID
  19. struts教程笔记5
  20. echarts-wordcloud 热词云使用

热门文章

  1. 2022-2028年中国超声波探伤仪行业市场现状调研及发展前景分析报告
  2. C++核心编程(一)
  3. 群论中的拉格朗日定理(子群的阶必然能整除群阶---数学
  4. tf.concat()详解
  5. ffmpeg architecture(中)
  6. CUDA C++程序设计模型
  7. 三维场景图:用于统一语义、三维空间和相机的结构
  8. CVPR2020论文解读:CNN合成的图片鉴别
  9. [C] Dijkstra算法——通过边实现松弛
  10. java线程触发_java线程