TensorFlow池化层-函数
池化层的作用如下-引用《TensorFlow实践》:
池化层的作用是减少过拟合,并通过减小输入的尺寸来提高性能。他们可以用来对输入进行降采样,但会为后续层保留重要的信息。只使用tf.nn.conv2d来减小输入的尺寸也是可以的,但是池化层的效率更高。
常见的TensorFlow提供的激活函数如下:(详细请参考http://www.tensorfly.cn/tfdoc/api_docs/python/nn.html)
1.tf.nn.max_pool(value, ksize, strides, padding, name=None)
Performs the max pooling on the input.
value: A 4-DTensorwith shape[batch, height, width, channels]and typefloat32,float64,qint8,quint8,qint32.ksize: A list of ints that has length >= 4. The size of the window for each dimension of the input tensor.strides: A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.padding: A string, either'VALID'or'SAME'. The padding algorithm.name: Optional name for the operation.
当我们的ksize=[1 3 3 1]式,我们取3X3模板池pool当中最大的数据当做中心点的值,strides作为滑动跳跃的间隔,代码如下所示:
import tensorflow as tf batch_size = 1
input_height = 3
input_width = 3
input_channels = 1
layer_input = tf.constant([
[
[[1.0],[0.2],[1.5]],
[[0.1],[1.2],[1.4]],
[[1.1],[0.4],[0.4]]
]
])
kernel = [batch_size, input_height, input_width,input_channels]
max_pool = tf.nn.max_pool(layer_input,kernel,[1,1,1,1],padding='VALID',name=None)
sess = tf.Session()
sess.run(max_pool)
输出结果如下(注意max_pool的输入的参数的维数一定要正确,否则会报错):

2.tf.nn.avg_pool(value, ksize, strides, padding, name=None)
Performs the average pooling on the input.
Each entry in output is the mean of the corresponding size ksize window in value.
value: A 4-DTensorof shape[batch, height, width, channels]and typefloat32,float64,qint8,quint8, orqint32.ksize: A list of ints that has length >= 4. The size of the window for each dimension of the input tensor.strides: A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.padding: A string, either'VALID'or'SAME'. The padding algorithm.name: Optional name for the operation.
跳跃遍历一个张量,并将被卷积核覆盖的各深度值去平均。当整个卷积核都非常重要时,若需要实现值的缩减,平均池化非常有用,例如输入张量宽度和高度很大,但深度很小的情况。
import tensorflow as tf batch_size = 1
input_height = 3
input_width = 3
input_channels = 1
layer_input = tf.constant([
[
[[1.0],[1.0],[1.0]],
[[1.0],[0.5],[0.0]],
[[0.0],[0.0],[0.0]]
]
])
kernel = [batch_size, input_height, input_width,input_channels]
avg_pool = tf.nn.mavg_pool(layer_input,kernel,[1,1,1,1],padding='VALID',name=None)
sess = tf.Session()
sess.run(avg_pool)
输出结果如下:(1.0+1.0+1.0+0.5+0.0+0.0+0.0+0.0)/9=0.5

TensorFlow池化层-函数的更多相关文章
- TensorFlow 池化层
在 TensorFlow 中使用池化层 在下面的练习中,你需要设定池化层的大小,strides,以及相应的 padding.你可以参考 tf.nn.max_pool().Padding 与卷积 pad ...
- tensorflow 1.0 学习:池化层(pooling)和全连接层(dense)
池化层定义在 tensorflow/python/layers/pooling.py. 有最大值池化和均值池化. 1.tf.layers.max_pooling2d max_pooling2d( in ...
- tensorflow的卷积和池化层(二):记实践之cifar10
在tensorflow中的卷积和池化层(一)和各种卷积类型Convolution这两篇博客中,主要讲解了卷积神经网络的核心层,同时也结合当下流行的Caffe和tf框架做了介绍,本篇博客将接着tenso ...
- tensorflow中的卷积和池化层(一)
在官方tutorial的帮助下,我们已经使用了最简单的CNN用于Mnist的问题,而其实在这个过程中,主要的问题在于如何设置CNN网络,这和Caffe等框架的原理是一样的,但是tf的设置似乎更加简洁. ...
- tensorflow CNN 卷积神经网络中的卷积层和池化层的代码和效果图
tensorflow CNN 卷积神经网络中的卷积层和池化层的代码和效果图 因为很多 demo 都比较复杂,专门抽出这两个函数,写的 demo. 更多教程:http://www.tensorflown ...
- 『TensorFlow』卷积层、池化层详解
一.前向计算和反向传播数学过程讲解
- 第十三节,使用带有全局平均池化层的CNN对CIFAR10数据集分类
这里使用的数据集仍然是CIFAR-10,由于之前写过一篇使用AlexNet对CIFAR数据集进行分类的文章,已经详细介绍了这个数据集,当时我们是直接把这些图片的数据文件下载下来,然后使用pickle进 ...
- 学习笔记TF014:卷积层、激活函数、池化层、归一化层、高级层
CNN神经网络架构至少包含一个卷积层 (tf.nn.conv2d).单层CNN检测边缘.图像识别分类,使用不同层类型支持卷积层,减少过拟合,加速训练过程,降低内存占用率. TensorFlow加速所有 ...
- 基于深度学习和迁移学习的识花实践——利用 VGG16 的深度网络结构中的五轮卷积网络层和池化层,对每张图片得到一个 4096 维的特征向量,然后我们直接用这个特征向量替代原来的图片,再加若干层全连接的神经网络,对花朵数据集进行训练(属于模型迁移)
基于深度学习和迁移学习的识花实践(转) 深度学习是人工智能领域近年来最火热的话题之一,但是对于个人来说,以往想要玩转深度学习除了要具备高超的编程技巧,还需要有海量的数据和强劲的硬件.不过 Tens ...
随机推荐
- 死磕安卓前序:MVP架构探究之旅—基础篇
前言 了解相关更多技术,可参考<我就死磕安卓了,怎么了?>,接下来谈一谈我们来学习一下MVP的基本认识. 大家对MVC的架构模式再熟悉不过.今天我们就学习一下MVP架构模式. MVC和MV ...
- spark submit参数及调优
park submit参数介绍 你可以通过spark-submit --help或者spark-shell --help来查看这些参数. 使用格式: ./bin/spark-submit \ ...
- Django框架之第二篇
一.知识点回顾 1.MTV模型 model:模型,和数据库相关的 template:模板,存放html文件,模板语法(目的是将变量如何巧妙的嵌入到HTML页面中). views:视图函数 另加urls ...
- HTML&javaSkcript&CSS&jQuery&ajax(11)
1.localStorage 没有 时间的限制数据存储, sessionStorage 针对一个session的存储,首先检查浏览器是否支持对这两个的存储, ifI(type(Storage)!==& ...
- poj2417 bsgs算法非逆元模板,用于求解A^x=B(mod C)的方程
参考博客 https://blog.csdn.net/clover_hxy/article/details/50683832关于欧拉定理推论的证明 https://www.cnblogs.com/as ...
- getComputedStyle()用法详解
那如果元素即没有在style属性中设置宽高,也没有在样式表中设置宽高,还能用getComputedStyle或currentStyle获取吗?答案是getComputedStyle可以,current ...
- centos7.5上一步步部署jumpserver
1.基础环境:centos7.5:关闭防火墙和selinux 2.修改字符集,否则可能会报input/output error 的问题,因为日志里打印了中文 [root@xzw ~]# localed ...
- axure交互样式(下拉列表和矩形)
*****矩形交互样式之单选按钮*****1.账号输入框.密码输入框等文本框实现效果:输入框获取焦点时边框是蓝色,失 去焦点时边框为红色: 2.实现思路:边框用矩形来设置选中和未选中.禁用和启用即可 ...
- pycharm安装mysql驱动包
新的环境配置pycharm的项目时,发现pycharm不能连接到mysql数据库.由于安了java环境但是还没配置相关的库,并且jetbrains家的IDE一般都是java写的,于是猜想可能是java ...
- Leetcode刷题第20天
一.找树左下角的值 题目:513. Find Bottom Left Tree Value C++ Soution 1: /** * Definition for a binary tree node ...