117、TensorFlow变量共享
# sharing variables
# Tensorflow supports two ways of sharing variables
# 1、Explicitly passing tf.Variable objects around
# 2、Implicitly wrapping tf.Variable objects within tf.variable_scope objects
# For example , let's write a function to create a convolutional / relu layer
import tensorflow as tf
def conv_relu(input, kernel_shape, bias_shape):
# Create variable named "weights"
weights = tf.get_variable("weights", kernel_shape, initializer=tf.random_normal_initializer())
# Create variable named "biases"
biases = tf.get_variable("biases", bias_shape, initializer=tf.constant_initializer(0.0))
# stride表示步长 , weight表示卷积核 , padding 表示卷积核是否可以停留在图像的边缘
conv = tf.nn.conv2d(input, weights, strides=[1, 1, 1, 1], padding='SAME')
return tf.nn.relu(conv + biases) # 这个函数使用了简写的weights和biases
# 在声明的时候是有帮助的,
# 但是在真实的模型中,我们更想要以下的卷积层,重复调用这个函数是不会起作用的
input1 = tf.random_normal([1, 10, 10, 32])
input2 = tf.random_normal([1, 20, 20, 32])
x = conv_relu(input1, kernel_shape=[5, 5, 32, 32], bias_shape=32)
# This fails 不支持重复调用 , 因为想要的行为还不清楚
# 是创建新的变量还是使用现有的变量
# x = conv_relu(x, kernel_shape=[5, 5, 32, 32], bias_shape=[32])
117、TensorFlow变量共享的更多相关文章
- TF Boys (TensorFlow Boys ) 养成记(三): TensorFlow 变量共享
上次说到了 TensorFlow 从文件读取数据,这次我们来谈一谈变量共享的问题. 为什么要共享变量?我举个简单的例子:例如,当我们研究生成对抗网络GAN的时候,判别器的任务是,如果接收到的是生成器生 ...
- 118、TensorFlow变量共享(二)
import tensorflow as tf # 在不同的变量域中调用conv_relu,并且声明我们想创建新的变量 def my_image_filter(input_images): with ...
- Tensorflow 变量的共享
https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ tens ...
- TensorFlow学习笔记3——变量共享
因为最近在研究生成对抗网络GAN,在读别人的代码时发现了 with tf.variable_scope(self.name_scope_conv, reuse = reuse): 这样一条语句,查阅官 ...
- TensorFlow学习笔记4——变量共享
因为最近在研究生成对抗网络GAN,在读别人的代码时发现了 with tf.variable_scope(self.name_scope_conv, reuse = reuse): 这样一条语句,查阅官 ...
- 如何在Exe和BPL插件中实现公共变量共享及窗口溶入技术Demo源码
如何在Exe和BPL插件中实现公共变量共享及窗口溶入技术Demo源码 1.Delphi编译方式介绍: 当我们在开发一个常规应用程序时,Delphi可以让我们用两种方式使用VCL,一种是把VCL中的申明 ...
- tensorflow变量-【老鱼学tensorflow】
在程序中定义变量很简单,只要定义一个变量名就可以,但是tensorflow有点类似在另外一个世界,因此需要通过当前的世界中跟tensorlfow的世界中进行通讯,来告诉tensorflow的世界中定义 ...
- tensorflow变量
tensorflow变量: 1.神经网络中的参数权重,偏置等可以作为张量保存到tensorflow的变量中 2.tensorflow变量必须被初始化 3.可被保存到文件中,下次使用重新加载即可 ten ...
- c++ 变量共享内存-联合(union)
共享内存极少使用,所以这里我们仅作了解. .将几个变量放在相同的内存区,但其中只有一个变量在给定时刻有有效值. .程序处理许多不同类型的数据,但是一次只处理一种.要处理的类型在执行期间才能确定. .在 ...
随机推荐
- C#计算两个日期的相隔天数
DateTime start = Convert.ToDateTime(dateStart.ToShortDateString()); DateTime end = Convert.ToDateTim ...
- 【报错】An error happened during template parsing (template: "class path resource [templates/hello1.html]")
页面显示: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing t ...
- 虚拟机环境搭建/修改VMware虚拟机固定IP
VMware Workstation安装CentOS7.0 详情教程: centos7.0下载地址:http://isoredirect.centos.org/centos/7/isos/x86_64 ...
- Lua中C API栈操作
向栈中压入数据: lua_pushnil(lua_State*); lua_pushboolean(lua_State*, bool); lua_pushnumber(lua_State*, lua_ ...
- 《剑指offer》面试题7 用两个栈实现队列 Java版
书中方法:队列是先进先出的,栈是先进后出的,试想把一串数压入A栈,接着一个个出栈并压入B栈,便会完成"头在下"到"头在上"的转变.B栈内还有元素时,直接出栈表示 ...
- Assembly language 再读---续
前面已经写到了第三章的数据类型 的那一部分 接下来是一些关于伪指令和其他杂七杂八的东西 1. 当前地址计数器: $ 常用于 计算数组以及字符串的长度,如: .data list db ,,,,, ...
- C Sleepy Kaguya
链接:https://ac.nowcoder.com/acm/contest/338/C来源:牛客网 题目描述 Houraisan☆Kaguya is the princess who lives i ...
- .ef core 多对对关系的关联方法
最近在用.net core 重构博客,在使用ef core连表查询时,遇到了一些问题.记录一下. 关系:一个博客可以有多个标签,一个标签可以属于多个博客,博客和标签之间存在多对多的关系 下面是实体代码 ...
- MySQL语句优化方法(简单版)
基础回顾: sql语句是怎么样运行的? 一般来说,客户端发送sql语句到数据库服务器——数据库服务器进行运算并返回结果——客户端显示sql语句运行结果. 在本地运行时以workbench为例,客户端为 ...
- day20 python异常处理 try except
day20 python 一.异常处理 1.什么是异常, 常见异常有: 逻辑错误 ''' name Traceback (most recent call last): ...