1. import tensorflow as tf
  2. # 在不同的变量域中调用conv_relu,并且声明我们想创建新的变量
  3. def my_image_filter(input_images):
  4. with tf.variable_scope("conv1"):
  5. # Variables created here will be named "conv1/weights" ,"conv1/biases"
  6. relu1 = conv_relu(input_images, [5, 5, 32, 32], [32])
  7. with tf.variable_scope("conv2"):
  8. # Variables created here will be named "conv2/weights" , "conv2/biases"
  9. return conv_relu(relu1, [5, 5, 32, 32], [32])
  10.  
  11. # 如果你想分享变量,你有两个选择,第一你可以创建一个有相同名字的变量域,使用reuse=True
  12. with tf.variable_scope("model"):
  13. output1 = my_image_filter(input1)
  14. with tf.variable_scope("model", reuse=True): output2 = my_image_filter(input2)
  15.  
  16. # 你也可以调用scope.reuse_variables()来触发一个重用:
  17. with tf.variable_scope("model") as scope:
  18. output1 = my_image_filter(input1)
  19. scope.reuse_variables()
  20. output2 = my_image_filter(input2)
  21.  
  22. # 因为解析一个变量域的名字是有危险的
  23. # 通过一个变量来初始化另一个变量也是可行的
  24. with tf.variable_scope("model") as scope:
  25. output1 = my_image_filter(input1)
  26. with tf.variable_scope(scope, reuse=True):
  27. output2 = my_image_filter(input2)

118、TensorFlow变量共享(二)的更多相关文章

  1. TF Boys (TensorFlow Boys ) 养成记(三): TensorFlow 变量共享

    上次说到了 TensorFlow 从文件读取数据,这次我们来谈一谈变量共享的问题. 为什么要共享变量?我举个简单的例子:例如,当我们研究生成对抗网络GAN的时候,判别器的任务是,如果接收到的是生成器生 ...

  2. 117、TensorFlow变量共享

    # sharing variables # Tensorflow supports two ways of sharing variables # 1.Explicitly passing tf.Va ...

  3. Tensorflow 变量的共享

    https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ tens ...

  4. TensorFlow学习笔记3——变量共享

    因为最近在研究生成对抗网络GAN,在读别人的代码时发现了 with tf.variable_scope(self.name_scope_conv, reuse = reuse): 这样一条语句,查阅官 ...

  5. 4、TensorFlow基础(二)常用API与变量作用域

    1.图.操作和张量 TensorFlow 的计算表现为数据流图,所以 tf.Graph 类中包含一系列表示计算的操作对象(tf.Operation),以及在操作之间流动的数据 — 张量对象(tf.Te ...

  6. TensorFlow学习笔记4——变量共享

    因为最近在研究生成对抗网络GAN,在读别人的代码时发现了 with tf.variable_scope(self.name_scope_conv, reuse = reuse): 这样一条语句,查阅官 ...

  7. tensorflow笔记(二)之构造一个简单的神经网络

    tensorflow笔记(二)之构造一个简单的神经网络 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7425200.html ...

  8. tensorflow常用函数(二)

    一.变量相关的函数 1)tf.train.list_variables(ckpt_dir_or_file)    Returns list of all variables in the checkp ...

  9. tensorflow学习笔记二:入门基础 好教程 可用

    http://www.cnblogs.com/denny402/p/5852083.html tensorflow学习笔记二:入门基础   TensorFlow用张量这种数据结构来表示所有的数据.用一 ...

随机推荐

  1. servlet--获取类路径下资源

     context 获取真实路径(*****) 还可以使用ServletContext对象来获取Web应用下的资源,例如在hello应用的根目录下创建a.txt文件,现在想在Servlet中获取这个资源 ...

  2. WPS for linux 中不能切换到中文输入法

    转载自:http://blog.sciencenet.cn/blog-200199-1032795.html 尽管安装有中文输入法,wps有时仍然不能切换到中文输入法,此问题解决方案如下: 根账户下打 ...

  3. 凸包模板——Graham扫描法

    凸包模板--Graham扫描法 First 标签: 数学方法--计算几何 题目:洛谷P2742[模板]二维凸包/[USACO5.1]圈奶牛Fencing the Cows yyb的讲解:https:/ ...

  4. 2.etcd集群的安装(cfssl版)

    etcd的安装注意两点 1.systemd的配置文件   2. 证书 1. 解决 systemd的问题,想安装指定版本的etcd可以通过 yum方式安装 etcd 可以获得 systemc 和 etc ...

  5. Leetcode Lect1 String相关题目

    Java 的 String 类基本用法介绍:http://www.runoob.com/java/java-string.html Java 的 String.substring 函数:https:/ ...

  6. C# json格式的序列化与反序列化

    使用C#,来序列化对象成为Json格式的数据,以及如何反序列化Json数据到对象 Json[javascript对象表示方法],它是一个轻量级的数据交换格式,我们可以很简单的来读取和写它,并且它很容易 ...

  7. Bootstrap-带语境色彩的面板

    使用语境状态类 panel-primary.panel-success.panel-info.panel-warning.panel-danger,来设置带语境色彩的面板,实例如           ...

  8. JS变量连续赋值

    下面就是这个经典案例: var a = {n: 1}; var b = a; a.x = a = {n: 2}; console.log(a);console.log(b); console.log( ...

  9. 2019-1-24-WPF-文字描边

    title author date CreateTime categories WPF 文字描边 lindexi 2019-01-24 19:47:18 +0800 2019-1-24 19:40:7 ...

  10. 一、UC中文调试

    一.只支持UC浏览器,版本号6.2.3831.3,复制resources.pak到UC安装目录下,覆盖同名文件即可