import tensorflow as tf
# 在不同的变量域中调用conv_relu,并且声明我们想创建新的变量
def my_image_filter(input_images):
with tf.variable_scope("conv1"):
# Variables created here will be named "conv1/weights" ,"conv1/biases"
relu1 = conv_relu(input_images, [5, 5, 32, 32], [32])
with tf.variable_scope("conv2"):
# Variables created here will be named "conv2/weights" , "conv2/biases"
return conv_relu(relu1, [5, 5, 32, 32], [32]) # 如果你想分享变量,你有两个选择,第一你可以创建一个有相同名字的变量域,使用reuse=True
with tf.variable_scope("model"):
output1 = my_image_filter(input1)
with tf.variable_scope("model", reuse=True): output2 = my_image_filter(input2) # 你也可以调用scope.reuse_variables()来触发一个重用:
with tf.variable_scope("model") as scope:
output1 = my_image_filter(input1)
scope.reuse_variables()
output2 = my_image_filter(input2) # 因为解析一个变量域的名字是有危险的
# 通过一个变量来初始化另一个变量也是可行的
with tf.variable_scope("model") as scope:
output1 = my_image_filter(input1)
with tf.variable_scope(scope, reuse=True):
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. HTML DOM cursor 属性

    值 描述 url 需被使用的自定义光标的URL 注释:请在此列表的末端始终定义一种普通的光标,以防没有由 URL 定义的可用光标. default 默认光标(通常是一个箭头) auto 默认.浏览器设 ...

  2. Hibernate入门1

    Hibernate概述: 1. 什么是框架: 写程序,在使用框架之后,帮我们实现一部分的功能,使用框架的好处可以少写一部分代码实现功能 2. 什么是hibernate框架: hibernate框架应用 ...

  3. JavaScript LinkedList

    function LinkedList() { var Node = function(element) { this.element = element; this.next = null } va ...

  4. 《JAVA设计模式》之解释器模式(Interpreter)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述解释器(Interpreter)模式的: 解释器模式是类的行为模式.给定一个语言之后,解释器模式可以定义出其文法的一种表示,并同时提供一个 ...

  5. 《JAVA设计模式》之备忘录模式(Memento)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述备忘录(Memento)模式的: 备忘录模式又叫做快照模式(Snapshot Pattern)或Token模式,是对象的行为模式. 备忘录 ...

  6. Python 学习笔记15 类 - 继承

    我们在编程的过程中,并非都是要重头开始.比如其他人已经有现成的类,我们可以使用其他找人编写的类.术语称之为: 继承. 当一个类继承例外一个类时,它可以获得这个类的所有属性和方法:原有的类称之为 父类, ...

  7. java_第一年_JavaWeb(9)

    JavaBean是一个遵循某种特定写法的Java类,有以下特点: 必需具有一个无参的构造函数 属性必需私有化 私有化的属性必需通过public类型的方法暴露给其它程序,其方法命名也有一定的规范 范例: ...

  8. python学习第六天--匿名函数、过滤、映射

    匿名函数 lambda表达式 过滤器 filter(判断函数,可迭代对象) 会根据提供的函数对指定序列做过滤 映射 map(判断函数,可迭代对象) 会根据提供的函数对指定序列做映射

  9. Server Tomcat v8.5 Server at localhost failed to start.

    问题描述:新建了一个项目,建立servlet文件然后改了下@WebServlet("floorButtonServlet")映射的路径,重启debug之后服务器启动失败. 在网上查 ...

  10. google+ sign in and get the oauth token 转摘:https://gist.github.com/ianbarber/5170508

    package com.example.anothersignintest;   import java.io.IOException;   import com.google.android.gms ...