name&variable scope
来源:互联网 发布:ubuntu daemon 编辑:程序博客网 时间:2024/06/06 01:12
http://blog.csdn.net/u012436149/article/details/53081454
name&variable scope
水平有限,如有错误,请指正!
在tensorflow中,有两个scope, 一个是name_scope一个是variable_scope,这两个scope到底有什么区别呢?
先看第一个程序:
- 1
- 2
- 3
- 4
- 5
- 6
输出为:
hello/
arr1:0
scope_name:
可以看出:
- tf.name_scope() 返回的是 一个string,”hello/”
- 在name_scope中定义的variable的name并没有 “hello/”前缀
- tf.get_variable_scope()的original_name_scope 是空
第二个程序:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
输出为:
- 1
- 2
- 3
- 4
- 5
可以看出:
- tf.variable_scope() 返回的是一个 op对象
- variable_scope中定义的variable 的name加上了”hello/”前缀
- tf.get_variable_scope()的original_name_scope 是 嵌套后的scope name
第三个程序:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
可以看出:variable scope
和name scope
都会给op
的name
加上前缀
对比三个个程序可以看出:
- name_scope对 get_variable()创建的变量 的名字不会有任何影响,而创建的
op
会被加上前缀. - tf.get_variable_scope() 返回的只是 variable_scope,不管 name_scope.所以以后我们在使用tf.get_variable_scope().reuse_variables() 时可以无视name_scope
其它
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
- 5
name_scope可以用来干什么
典型的 TensorFlow 可以有数以千计的节点,如此多而难以一下全部看到,甚至无法使用标准图表工具来展示。为简单起见,我们为op/tensor
名划定范围,并且可视化把该信息用于在图表中的节点上定义一个层级。默认情况下, 只有顶层节点会显示。下面这个例子使用tf.name_scope在hidden命名域下定义了三个操作:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
结果是得到了下面三个操作名:
hidden/alpha
hidden/weights
hidden/biases
name_scope 是给op_name加前缀, variable_scope是给get_variable()创建的变量的名字加前缀。
tf.variable_scope有时也会处理命名冲突
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
其它
- tf.name_scope(None) 有清除name scope的作用
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
variable_scope可以用来干什么
variable_scope 用来管理 variable 详见variable_scope
总结
简单来看
1. 使用tf.Variable()
的时候,tf.name_scope()
和tf.variable_scope()
都会给 Variable
和 op
的 name
属性加上前缀。
2. 使用tf.get_variable()
的时候,tf.name_scope()
就不会给 tf.get_variable()
创建出来的Variable
加前缀。
- name&variable scope
- tensorflow:name&variable scope
- 转载!tensorflow name scope和variable scope
- tensorflow学习笔记(十七):name&variable scope
- What's the difference of name scope and a variable scope in tensorflow?
- What's the difference of name scope and a variable scope in tensorflow?
- JS variable scope
- [Ruby] Ruby Variable Scope
- [Javascript] variable, scope, scope chain, execution context
- python name scope
- python namespace and variable scope
- Ruby Variable Scope 简单讲解
- tf.name_scope&tf.variable scope
- tensorflow学习笔记: variable scope
- empty variable name
- empty variable name
- PHP's numeric variable name...
- javascript variable's scope , 变量 范围
- 模板二维数组
- 三目运算符的使用方法
- Centos创建用户几组的相关命令
- 一个小型web项目的问题整合
- 计算机视觉入门
- name&variable scope
- 一个有用的shell脚本
- Hibernate基本配置
- 【ServletFileUpLoad】上传本地文件到服务器
- 共享图书横空出世一本书看十天只需一块钱
- luogu 1613 跑路
- 图片上传
- 图分析与可视化
- spring自定义注解