当前位置:网站首页>(TensorFlow) - detailed explanation of tf.variable_scope and tf.name_scope
(TensorFlow) - detailed explanation of tf.variable_scope and tf.name_scope
2022-08-04 06:06:00 【Big Yellow Cat No. 1】
Learning tensorflow in the past few days, I have seen about tf.variable_scope and tf.name_scop, but I have not had a deep understanding of their functions.Reprint a blog:
The difference between tf.name_scope() and tf.variable_scope() in Tensorflow Record the effect,Forget one side later.
Briefly say it here:
tf.variable_scope allows variables to have the same name, including the variables obtained by tf.get_variable and the variables of tf.Variable
tf.name_scope allows variables to have the same name, only limited to tf.Variable variables
Example:
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.nameprint a2.nameprint a3.nameprint a4.nameOutput:
V1/a1:0
V1/a2:0
V2/a1:0
V2/a2:0
Example 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.nameprint a2.nameprint a3.nameprint a4.nameError: Variable a1 already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:
Replace with the following code to execute
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.nameprint a2.name# print a3.nameprint a4.nameOutput:
V1/a2:0
V2/a2:0
边栏推荐
- 安装dlib踩坑记录,报错:WARNING: pip is configured with locations that require TLS/SSL
- [Deep Learning 21 Days Learning Challenge] Memo: What does our neural network model look like? - detailed explanation of model.summary()
- Redis持久化方式RDB和AOF详解
- sql中group by的用法
- 剑指 Offer 2022/7/4
- 记一次flink程序优化
- Usage of RecyclerView
- Simple and clear, the three paradigms of database design
- Postgresql 快照
- flink-sql所有表连接器
猜你喜欢

Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL

ISCC2021——web部分

线性回归02---波士顿房价预测

Th in thymeleaf: href use notes

Thoroughly understand box plot analysis

【go语言入门笔记】13、 结构体(struct)

win云服务器搭建个人博客失败记录(wordpress,wamp)

TensorFlow2 study notes: 4. The first neural network model, iris classification

npm install dependency error npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND

flink问题整理
随机推荐
TensorFlow2学习笔记:4、第一个神经网模型,鸢尾花分类
yolov3中数据读入(一)
IvNWJVPMLt
WARNING: sql version 9.2, server version 11.0.Some psql features might not work.
NFT市场开源系统
判断字符串是否有子字符串重复出现
Matplotlib中的fill_between;np.argsort()函数
Delphi-C side interesting menu operation interface design
Kubernetes集群安装
剑指 Offer 2022/7/12
剑指 Offer 2022/7/5
动手学深度学习_卷积神经网络CNN
ISCC2021——web部分
【深度学习21天学习挑战赛】1、我的手写被模型成功识别——CNN实现mnist手写数字识别模型学习笔记
with recursive用法
剑指 Offer 2022/7/8
Postgresql 快照
线性回归简介01---API使用案例
【CV-Learning】图像分类
SQL练习 2022/7/3