Tensorflow函数——tf.variable_scope()
来源:互联网 发布:手机无法加入网络 编辑:程序博客网 时间:2024/05/08 18:34
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"
共享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
通过捕获范围并设置重用来共享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
为了防止意外共享variable,当在非重用范围内获取现有variable时,我们引发异常。
with tf.variable_scope("foo"): v = tf.get_variable("v", [1]) v1 = tf.get_variable("v", [1]) # Raises ValueError("... v already exists ...").
同样,当尝试获取在重用模式下不存在的variable时,我们引发异常。
with tf.variable_scope("foo", reuse=True): v = tf.get_variable("v", [1]) # Raises ValueError("... v does not exists ...").
请注意,重用标志是继承的:如果我们打开一个重用的范围,那么它的所有子范围也会变得重用。
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:在此范围中创建的变量类型(默认为传递范围中的类型,或从父范围继承)
返回:
可以捕获和重复使用的范围。
阅读全文
0 0
- Tensorflow函数——tf.variable_scope()
- TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- Tensorflow函数说明(4)—— variable_scope/name_scope
- tensorflow学习之路(2-2):tf.variable_scope(),tf.name_scope(),tf.get_variable()的认识(补充)
- 【TensorFlow】变量管理tf.get_variables/tf.Variable/tf.variable_scope的应用(七)
- tensorflow variable_scope,tf.name_scope, tf.variable, tf.get_varible
- Tensorflow中tf.get_variable和tf.variable_scope的使用
- tensorflow——tf.one_hot以及tf.sparse_to_dense函数
- TensorFlow函数——tf.variable( )
- TensorFlow函数——tf.placeholder()
- Tensorflow函数——tf.set_random_seed(seed)
- tensorflow的共享变量,tf.Variable(),tf.get_variable(),tf.Variable_scope(),tf.name_scope()联系与区别:
- tensorflow的共享变量,tf.Variable(),tf.get_variable(),tf.Variable_scope(),tf.name_scope()联系与区别
- tensorflow的共享变量,tf.Variable(),tf.get_variable(),tf.Variable_scope(),tf.name_scope()联系与区别
- tensorflow学习之路(2-1):tf.variable_scope(), tf.name_scope(), tf.get_variable()的认识
- tensorflow 变量生成 变量管理 tf.Variable & tf.get_variable & tf.variable_scope
- tensorflow 中 variable_scope 与name_scope函数解析
- 转载!Tensorflow函数——tf.set_random_seed(seed)
- Android内部存储和外部存储
- JUnit4笔记(三)---JUnit的测试套件和参数化设置
- iOS程序员利用分页和模糊查询技术实现一个App接口
- 算法:迷宫求解(栈的应用)-数据结构(8)
- to_date() 整理
- Tensorflow函数——tf.variable_scope()
- socket.io (nodejs+express)
- swift中的沙盒路径(包含自定义文件路径)
- 关于Gif播放的实现
- opencv2.4.9移植到arm
- 5.14特长生模拟 门票
- HashMap集合和TreeMap集合
- Java实例-Swing简易计算器(加,减,乘,数)
- 登录oracle数据库时常用的操作命令整理