代码:

import tensorflow as tf# tf.name_scope 主要结合 tf.Variable() 来使用,方便参数命名管理。
# 创建一个命名空间
with tf.name_scope("conv1"):weights1 = tf.Variable([1.0,2.0], name='weights')bias1 = tf.Variable([0.1], name='bias')
# 创建另外一个命名空间来定义变量
with tf.name_scope("conv2"):weights2 = tf.Variable([2.0,2.0], name='weights')bias2 = tf.Variable([0.2], name='bias')# weights1 和 weights2 这两个引用名指向了不同的空间,不会冲突
print(weights1.name)
print(weights1)
print(weights2.name)
print(weights2)# 执行完 with 里边的语句之后,这个 conv1/ 和 conv2/ 空间还是在内存中的
# 如果再次执行上面的代码,会再生成其他命名空间

运行结果:

conv1/weights:0
<tf.Variable 'conv1/weights:0' shape=(2,) dtype=float32_ref>
conv2/weights:0
<tf.Variable 'conv2/weights:0' shape=(2,) dtype=float32_ref>

代码:

# tf.variable_scope() 主要结合 tf.get_variable() 来使用,实现变量共享。with tf.variable_scope('vs1'):weights1 = tf.get_variable('weights', shape=[2,3])bias1 = tf.Variable([0.52], name='bias')# 变量必须已经定义过了,才能设置 reuse=True,否则会报错
with tf.variable_scope('vs1', reuse=True):weights2 = tf.get_variable('weights')bias2 = tf.Variable([0.52], name='bias')# 可以看到这两个引用名称指向的是同一个内存对象
print(weights1.name)
print(weights2.name)
print("===" * 20)
print(bias1.name)
print(bias2.name)

运行结果:

vs1/weights:0
vs1/weights:0
============================================================
vs1/bias:0
vs1_1/bias:0

Tensorflow— name/variable_scope相关推荐

  1. Tensorflow中的name_scope和variable_scope

    Tensorflow是一个编程模型,几乎成为了一种编程语言(里面有变量.有操作......). Tensorflow编程分为两个阶段:构图阶段+运行时. Tensorflow构图阶段其实就是在对图进行 ...

  2. Tensorflow name_scope和variable_scope的用法

    Tensorflow name_scope和variable_scope 的用法 简介 当一个神经网络比较复杂.参数比较多时,就比较需要一个比较好的方式来传递和管理这些参数.而Tensorflow提供 ...

  3. tensorflow中name_scope和variable_scope变量的使用

    1. variable_scope的使用 首先,使用variable_scope可以很方便的管理get_varibale. 如何确定 get_variable 的 prefixed name? 1.1 ...

  4. TensorFlow学习笔记(1):variable与get_variable, name_scope()和variable_scope()

    Variable tensorflow中有两个关于variable的op,tf.Variable()与tf.get_variable()下面介绍这两个的区别 使用tf.Variable时,如果检测到命 ...

  5. Tensorflow 之 name/variable_scope 变量管理

    name/variable_scope 的作用 充分理解 name / variable_scope TensorFlow 入门笔记 当一个神经网络比较复杂.参数比较多时,就比较需要一个比较好的方式来 ...

  6. TensorFlow基础笔记(13) tf.name_scope tf.variable_scope学习

    转载http://blog.csdn.net/jerr__y/article/details/60877873 1. 首先看看比较简单的 tf.name_scope('scope_name'). tf ...

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

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

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

  9. Tensorflow函数——tf.variable_scope()

    tf.variable_scope(name_or_scope,default_name=None,values=None,initializer=None,regularizer=None,cach ...

最新文章

  1. linux重启后出现control+D错误的解决
  2. 41 | 案例篇:如何优化 NAT 性能?(上)
  3. IDOC generation debug for One Order
  4. inDesign教程,如何将inDesign文档导出为 PDF 文件?
  5. 梯度消失的有效解决方法-batch normalization
  6. 记工软件 包工头记工软件 建筑记工软件 工程记工软件
  7. 帮助小姐姐破解加密压缩包(一)——暴力破解字典生成
  8. ICML 2021奖项公布!谷歌大脑摘得桂冠,田渊栋、陆昱成获荣誉提名!
  9. android内存碎片问题优化梳理
  10. BoundsChecker的使用
  11. SQL学习-数据库基础知识(1)
  12. vivo和小米鸿蒙系统哪个好,vivo和华为还有小米,哪个系统流畅度更好?
  13. excel合并两列内容_10.表格中如何将两列文本内容合并
  14. php 扑克牌洗牌算法,随机洗牌算法 | 学步园
  15. SNF快速开发平台2020版
  16. 企业微信裂变玩法有哪些?需要使用哪些工具?
  17. RecyclerView notifyDataSetChanged 导致图片闪烁的原因
  18. [解决Chrome禁止发送不安全的内网网络请求](ERR_FAILED)(How to fix Chrome block your insecure private network requests)
  19. excel2016 for mac 二维表转一维表
  20. Ruby-from百度百科

热门文章

  1. 2020 AI DEBATE即将召开, Judea Pearl、李飞飞等10多位顶级科学家参与 | AI日报
  2. 为什么数据库不应该使用外键?
  3. 沈向洋、华刚:读科研论文的三个层次、四个阶段与十个问题
  4. 入门大爆炸式发展的深度学习,你先要了解这4个最流行框架
  5. 150页在线书「几何深度学习」上线:利用对称性和不变性解决机器学习问题
  6. 祝贺!清华大学姚期智教授荣获2021届京都奖:“日本的诺贝尔奖”
  7. 【一周速递】计算机视觉/图像处理论文集
  8. 计算机视觉顶会CVPR2020接收论文列表已公布,1470篇上榜, 你的paper中了吗?
  9. 2015年二级c语言真题及答案,2015年计算机二级C语言测试题及答案(4)
  10. SAP WM 因Layout设置不对导致LX02报表查不到库存数据