import tensorflow as tf

with tf.variable_scope("foo"):
v = tf.get_variable("v", [1], initializer=tf.constant_initializer(1.0)) #with tf.variable_scope("foo"):
# v = tf.get_variable("v", [1]) with tf.variable_scope("foo", reuse=True):
v1 = tf.get_variable("v", [1])
print(v == v1) #with tf.variable_scope("bar", reuse=True):
# v = tf.get_variable("v", [1])

with tf.variable_scope("root"):
print(tf.get_variable_scope().reuse) with tf.variable_scope("foo", reuse=True):
print(tf.get_variable_scope().reuse) with tf.variable_scope("bar"):
print(tf.get_variable_scope().reuse) print(tf.get_variable_scope().reuse)

v1 = tf.get_variable("v", [1])
print(v1.name) with tf.variable_scope("foo",reuse=True):
v2 = tf.get_variable("v", [1])
print(v2.name) with tf.variable_scope("foo"):
with tf.variable_scope("bar"):
v3 = tf.get_variable("v", [1])
print(v3.name) v4 = tf.get_variable("v1", [1])
print(v4.name)

with tf.variable_scope("",reuse=True):
v5 = tf.get_variable("foo/bar/v", [1])
print(v5 == v3)
v6 = tf.get_variable("v1", [1])
print(v6 == v4)

吴裕雄 python 神经网络——TensorFlow 变量管理的更多相关文章

  1. 吴裕雄 python 神经网络——TensorFlow实现搭建基础神经网络

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def add_layer(inputs, in_ ...

  2. 吴裕雄 python 神经网络——TensorFlow 使用卷积神经网络训练和预测MNIST手写数据集

    import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...

  3. 吴裕雄 python 神经网络TensorFlow实现LeNet模型处理手写数字识别MNIST数据集

    import tensorflow as tf tf.reset_default_graph() # 配置神经网络的参数 INPUT_NODE = 784 OUTPUT_NODE = 10 IMAGE ...

  4. 吴裕雄 python 神经网络——TensorFlow 数据集高层操作

    import tempfile import tensorflow as tf train_files = tf.train.match_filenames_once("E:\\output ...

  5. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(4)

    # -*- coding: utf-8 -*- import glob import os.path import numpy as np import tensorflow as tf from t ...

  6. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(3)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  7. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(2)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  8. 吴裕雄 python 神经网络——TensorFlow 花瓣识别2

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  9. 吴裕雄 python 神经网络——TensorFlow 三层简单神经网络的前向传播算法

    import tensorflow as tf w1= tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1)) w2= tf.Variable( ...

随机推荐

  1. mac visual stdio 2019 自动格式化代码的选项

    1 打开Visual Stdio >点开菜单的visual stdio 的选项卡>首选项>文本编辑>行为>保存时格式化文档 (将这个选项 勾上)>确定 2 以后代码 ...

  2. DockerFile执行报错解决

    错误1: “docker build” requires exactly 1 argument.原因: 之前的命令是这样的: docker build -t nbCentos:1.0.0 , 不仔细看 ...

  3. c++ google glog模块安装和基本使用(ubuntu)环境

    1,如何安装 1 Git clone https://github.com/google/glog.git 2 cd glog 3 ./autogen.sh 4 ./configure --prefi ...

  4. flex space-between最后一行对齐问题的解决方案

    背景 常见的一个图文列表设计,通常是这样的,两端顶着容器,中间的间距平均分,如下图的某东商品列表的设计: 列表是这样自适应的,当视窗足够放多少个商品就放多少个,然后各个商品项目之间的间距平均分.由于每 ...

  5. Mobius反演定理-BZOJ2154

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 莫比乌斯定理(未 ...

  6. selenium通过cookies直接免密登录

    前提知识: 1.webdriver中提供了操作cookie的相关方法: get_cookies()                    获得cookie信息 add_cookie(cookie_di ...

  7. python字典里面列表排序

    #coding=utf8 #获取到的数据库ip,和负载数据,需要按照负载情况排序 a={u'1.8.1.14': [379, 368, 361, 358, 1363], u'9.2.4.3': [42 ...

  8. LOJ#6713. 「EC Final 2019」狄利克雷 k 次根 加强版

    题目描述 定义两个函数 \(f, g: \{1, 2, \dots, n\} \rightarrow \mathbb Z\) 的狄利克雷卷积 \(f * g\) 为: \[ (f * g)(n) = ...

  9. * ./common/http.js in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-opt

    vue项目报错如下,找到原因之后,其实超简单,请看: 原来是引入文件路径出现问题,想起刚刚引入了一个文件,一修改,果然药到病除! ----------------------------------- ...

  10. Angular NgModule(模块)

    NgModule 模块是Angular种一个重要的点,因为Angular的基本构造块就是NgModule.NgModule 会把相关的代码收集到一些功能集中,形成功能单元.在使用Angular CL ...