tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
来源:互联网 发布:孪生素数c语言 编辑:程序博客网 时间:2024/05/22 00:39
转:http://blog.csdn.net/lanchunhui/article/category/6505404
scope 命名方法
- 对于一个复杂的 tensorflow 模型会有很多个变量,
- tf.variable_scope() :提供了简单的命名空间技术以避免冲突;
- tf.get_variable():从同一个变量范围内获取或者创建;
- 见名知意,tf.Variable() variable 且以大写字母开头,该函数在于定义一个变量;tf.get_variable():可根据 name 值,返回该变量,如果该 name 不存在的话,则会进行创建;
1. name_scope()
先说结论:
- tf.get_variable() 以及 tf.Variable() 是 TensorFlow 中创建变量的两种主要方式;
- 如果在 tf.name_scope() 环境下分别使用 tf.get_variable() 和 tf.Variable(),两者的主要区别在于
- tf.get_variable() 创建的变量名不受 name_scope 的影响;
- tf.get_variable() 创建的变量,name 属性值不可以相同;tf.Variable() 创建变量时,name 属性值允许重复(底层实现时,会自动引入别名机制)
- 此外 tf.get_variable() 与 tf.Variable() 相比,多了一个 initilizer (初始化子)可选参数;
- tf.Variable() 对应地多了一个 initial_value 关键字参数,也即对于 tf.Variable 创建变量的方式,必须显式初始化;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
输出为:
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
2. variable_scope()
一个双层嵌套名称空间:
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
3. get_variable()
get_variable() 函数的行为依赖于 reuse 的状态:
case1:reuse 设置为 False,创建并返回新变量:
- 1
- 2
- 3
- 1
- 2
- 3
case2:reuse 设置为 True,将会按照给定的名字在以存的变量中搜寻:
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
0 0
- tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- 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的共享变量,tf.Variable(),tf.get_variable(),tf.Variable_scope(),tf.name_scope()联系与区别
- 彻底弄懂tf.Variable、tf.get_variable、tf.variable_scope以及tf.name_scope异同
- tensorflow variable_scope,tf.name_scope, tf.variable, tf.get_varible
- tf.get_variable 和tf.variable_scope
- tf.get_variable 和tf.variable_scope
- tf.get_variable 和tf.variable_scope
- tf.name_scope and tf.variable_scope
- tf.name_scope&tf.variable scope
- tensorflow学习之路(2-1):tf.variable_scope(), tf.name_scope(), tf.get_variable()的认识
- tensorflow学习之路(2-2):tf.variable_scope(),tf.name_scope(),tf.get_variable()的认识(补充)
- tf.variable_scope和tf.name_scope的用法
- tf.variable_scope与tf.name_scope不同之处
- 基于zookeeper实现分布式锁
- python编程快速上手 第6章 实践项目 自己写的答案
- CNN数据增强(1)
- 使用Nvidia Jetson TX1,在新的C++工程中调用caffe
- 大型网站架构之分布式消息队列
- tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- 使用Bundle.putSerializable() 在Activity中交换数据
- 【搜索】洛谷 P1460 健康的荷斯坦奶牛 Healthy Holsteins
- Linux音频设备驱动_OSS驱动框架(二)————OSS驱动架构代码vmsnd.c
- Android Studio低版本Gradle的项目升级到高版本
- Hbase架构与原理
- vue2.0有哪些变化
- Caffe之网络输出
- Lua协程例子