tf.get_variable 和tf.variable_scope
来源:互联网 发布:怎么让手机网络变快 编辑:程序博客网 时间:2024/05/21 17:54
变量共享主要涉及到两个函数:
tf.get_variable(<name>, <shape>, <initializer>) 和 tf.variable_scope(<scope_name>)。
先来看第一个函数: tf.get_variable。
tf.get_variable 和tf.Variable不同的一点是,前者拥有一个变量检查机制,会检测已经存在的变量是否设置为共享变量,如果已经存在的变量没有设置为共享变量,TensorFlow 运行到第二个拥有相同名字的变量的时候,就会报错。
为了解决这个问题,TensorFlow 又提出了 tf.variable_scope 函数:它的主要作用是,在一个作用域 scope 内共享一些变量,可以有如下几种用法:
1)
with tf.variable_scope("image_filters") as scope: result1 = my_image_filter(image1) scope.reuse_variables() # or #tf.get_variable_scope().reuse_variables() result2 = my_image_filter(image2)
需要注意的是:最好不要设置 reuse 标识为 False,只在需要的时候设置 reuse 标识为 True。
2)
with tf.variable_scope("image_filters1") as scope1: result1 = my_image_filter(image1)with tf.variable_scope(scope1, reuse = True) result2 = my_image_filter(image2)
转载文章:
http://www.cnblogs.com/Charles-Wan/p/6200446.html
0 1
- tf.get_variable 和tf.variable_scope
- tf.get_variable 和tf.variable_scope
- tf.get_variable 和tf.variable_scope
- tf.get_variable tf.variable_scope tf.name_scope
- Tensorflow中tf.get_variable和tf.variable_scope的使用
- 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]Sharing Variables 共享权值【tf.get_variable 和 tf.variable_scope】
- TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_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异同
- tf.get_variable()
- tensorflow学习之路(2-1):tf.variable_scope(), tf.name_scope(), tf.get_variable()的认识
- tensorflow学习之路(2-2):tf.variable_scope(),tf.name_scope(),tf.get_variable()的认识(补充)
- tensorflow 变量生成 变量管理 tf.Variable & tf.get_variable & tf.variable_scope
- tf.variable_scope和tf.name_scope的用法
- Windows下使用DOS命令进入MySQL数据库
- 1.13 Codeforces 30D Kings Problem 贪心 计算几何
- Android上实现一个简单的天气预报APP(九) ListView展示城市列表、单击更新天气数据
- windows2008 server下安装ORACLE 11G
- fox 算法 mpi 实现
- tf.get_variable 和tf.variable_scope
- Linear regression of multiple features in Tensorflow
- Struts2与Spring整合
- python ftp的一个脚本
- ORM的理解
- libsvm中-b参数(matlab)
- 关于C++多态的学习
- QT之二级菜单
- BI选型流程建议