tf.variable_scope() and tf.name_scope()
https://blog.csdn.net/UESTC_C2_403/article/details/72328815
tf.variable_scope可以让变量有相同的命名,包括tf.get_variable得到的变量,还有tf.Variable的变量
tf.name_scope可以让变量有相同的命名,只是限于tf.Variable的变量
例如:
import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt;
with tf.variable_scope('V1'):
a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a2 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.variable_scope('V2'):
a3 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a4 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print a1.name
print a2.name
print a3.name
print a4.name
输出:
V1/a1:0
V1/a2:0
V2/a1:0
V2/a2:0
例子2:
import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt;
with tf.name_scope('V1'):
a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a2 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.name_scope('V2'):
a3 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a4 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print a1.name
print a2.name
print a3.name
print a4.name
报错:Variable a1 already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:
换成下面的代码就可以执行:
import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt;
with tf.name_scope('V1'):
# a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a2 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.name_scope('V2'):
# a3 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1))
a4 = tf.Variable(tf.random_normal(shape=[2,3], mean=0, stddev=1), name='a2')
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
# print a1.name
print a2.name
# print a3.name
print a4.name
输出:
V1/a2:0
V2/a2:0
tf.variable_scope() and tf.name_scope()相关推荐
- tf.Variable、tf.get_variable、tf.variable_scope、tf.name_scope、random、initializer
转自:tensorflow学习笔记(二十三):variable与get_variable TF.VARIABLE.TF.GET_VARIABLE.TF.VARIABLE_SCOPE以及TF.NAME_ ...
- tf.variable_scope和tf.name_scope的用法
tf.variable_scope可以让不同命名空间中的变量取相同的名字,无论tf.get_variable或者tf.Variable生成的变量 tf.name_scope具有类似的功能,但只限于tf ...
- tf.Variable、tf.get_variable、tf.variable_scope以及tf.name_scope
tf.Variable与tf.get_variable tensorflow提供了通过变量名称来创建或者获取一个变量的机制.通过这个机制,在不同的函数中可以直接通过变量的名字来使用变量,而不需要将变量 ...
- tf.variable_scope与tf.tf.get_variable
实验一. 不设置随机种子,使用不同的初始化方法 import tensorflow as tf; import numpy as np; import matplotlib.pyplot as plt ...
- 通俗理解tf.name_scope()、tf.variable_scope()
前言:最近做一个实验,遇到TensorFlow变量作用域问题,对tf.name_scope().tf.variable_scope()等进行了较为深刻的比较,记录相关笔记: tf.name_scope ...
- tf.name_scope() 和 tf.variable_scope() 的用法和玄机
2019独角兽企业重金招聘Python工程师标准>>> 一. name_scope 和 variable_scope的用途 用途1: 共享变量 TensorFlow (TF) 中,n ...
- tf.name_scope()与tf.variable_scope()
TensorFlow的tf.name_scope().tf.variable_scope()是两个作用域函数,一般与两个创建/调用变量的函数tf.variable() 和tf.get_variable ...
- tf.name_scope tf.variable_scope学习
1. 首先看看比较简单的 tf.name_scope('scope_name'). tf.name_scope 主要结合 tf.Variable() 来使用,方便参数命名管理. ''' Signatu ...
- TensorFlow基础笔记(13) tf.name_scope tf.variable_scope学习
转载http://blog.csdn.net/jerr__y/article/details/60877873 1. 首先看看比较简单的 tf.name_scope('scope_name'). tf ...
最新文章
- Apriori算法通俗详解_fpgrowth2_关联分析评估
- java美容美发项目下载_基于jsp的美容美发管理-JavaEE实现美容美发管理 - java项目源码...
- 代理模式、动态代理和面向方面
- 好文分享:我是如何在求职中把自己“推销”出去的
- 【科研绘图】Visio保存为PDF时去掉黑框
- 3ds Max制作一面飘扬的旗帜效果图
- 《软技能:代码之外的生存指南》一一35.2 找出你的短板
- Ubuntu 20.04 锐捷客户端安装记录
- 丁仲礼院士:深入理解碳中和的基本逻辑和技术需求
- 畅销书看得不过瘾?KU电子书包月服务了解一下
- VOIP技术连载之一 VOIP简介
- mongodb备份oplog_Mongodb 之 oplog进行数据备份恢复
- IT 如何把骨干留住
- 海康威视官方安装包(提供64位安装包)
- Java(JNI)Android使用JNI开发
- 24安装失败 spss win10_win10系统安装spss22.0软件的设置办法
- springboot 添加第三方jar包
- 惊爆:当Python代码遇到zip解压炸弹,未做防护的你后悔莫及!
- 静态时序分析 第三章 标准单元库
- 当数据分析遭遇心理动力学:用户深层次的情感需求浮出水面(万字长文,附实例分析)...
热门文章
- mysql semi join_MySQL 5.6 Semi join优化之materialization strategy
- python中的标识符能不能使用关键字_Python中的标识符不能使用关键字
- 一组超炫酷的动图,感受那让人窒息的数学之美!
- 这个让人看跪了的设计!实力证明,数学才是世界的最终boss!
- 深入探讨编程到底需要知道多少数学知识
- 如何在android客户端中做到自动检查数据更新?,UpdateHelper
- hadoop 2.7 java_Hadoop2.7环境搭建---Java环境变量
- python选择题题目_Python接口测试题(持续更新中)
- U盘安装Linux挂载cd,U盘安装Ubuntu Server CD-ROM挂载失败
- java io流学设置编码_Java学习日志(21-2-IO流-基本数据类型与字节数组对象与、编码解码)...