pytorch torch.nn.AdaptiveAvgPool2d()自适应平均池化函数详解


Posted in Python onJanuary 03, 2020

如题:只需要给定输出特征图的大小就好,其中通道数前后不发生变化。具体如下:

AdaptiveAvgPool2d

CLASStorch.nn.AdaptiveAvgPool2d(output_size)[SOURCE]

Applies a 2D adaptive average pooling over an input signal composed of several input planes.

The output is of size H x W, for any input size. The number of output features is equal to the number of input planes.

Parameters

output_size ? the target output size of the image of the form H x W. Can be a tuple (H, W) or a single H for a square image H x H. H and W can be either a int, or None which means the size will be the same as that of the input.

Examples

>>> # target output size of 5x7
>>> m = nn.AdaptiveAvgPool2d((5,7))
>>> input = torch.randn(1, 64, 8, 9)
>>> output = m(input)
>>> # target output size of 7x7 (square)
>>> m = nn.AdaptiveAvgPool2d(7)
>>> input = torch.randn(1, 64, 10, 9)
>>> output = m(input)
>>> # target output size of 10x7
>>> m = nn.AdaptiveMaxPool2d((None, 7))
>>> input = torch.randn(1, 64, 10, 9)
>>> output = m(input)
>>> input = torch.randn(1, 3, 3, 3)
>>> input
tensor([[[[ 0.6574, 1.5219, -1.3590],
   [-0.1561, 2.7337, -1.8701],
   [-0.8572, 1.0238, -1.9784]],
 
   [[ 0.4284, 1.4862, 0.3352],
   [-0.7796, -0.8020, -0.1243],
   [-1.2461, -1.7069, 0.1517]],
 
   [[ 1.4593, -0.1287, 0.5369],
   [ 0.6562, 0.0616, 0.2611],
   [-1.0301, 0.4097, -1.9269]]]])
>>> m = nn.AdaptiveAvgPool2d((2, 2))
>>> output = m(input)
>>> output
tensor([[[[ 1.1892, 0.2566],
   [ 0.6860, -0.0227]],
 
   [[ 0.0833, 0.2238],
   [-1.1337, -0.6204]],
 
   [[ 0.5121, 0.1827],
   [ 0.0243, -0.2986]]]])
>>> 0.6574+1.5219+2.7337-0.1561
4.7569
>>> 4.7569/4
1.189225
>>>

以上这篇pytorch torch.nn.AdaptiveAvgPool2d()自适应平均池化函数详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python获取一组汉字拼音首字母的方法
Jul 01 Python
Python算法之图的遍历
Nov 16 Python
Python中的探索性数据分析(功能式)
Dec 22 Python
Python实现统计给定列表中指定数字出现次数的方法
Apr 11 Python
如何利用python查找电脑文件
Apr 27 Python
pyspark 读取csv文件创建DataFrame的两种方法
Jun 07 Python
Python中的异常处理try/except/finally/raise用法分析
Feb 28 Python
Python参数解析模块sys、getopt、argparse使用与对比分析
Apr 02 Python
django 控制页面跳转的例子
Aug 06 Python
python加密解密库cryptography使用openSSL生成的密匙加密解密
Feb 11 Python
django使用JWT保存用户登录信息
Apr 22 Python
浅析Python 中的 WSGI 接口和 WSGI 服务的运行
Dec 09 Python
pytorch AvgPool2d函数使用详解
Jan 03 #Python
使用pyhon绘图比较两个手机屏幕大小(实例代码)
Jan 03 #Python
Python基础之函数原理与应用实例详解
Jan 03 #Python
对Pytorch中Tensor的各种池化操作解析
Jan 03 #Python
Python基础之高级变量类型实例详解
Jan 03 #Python
关于Pytorch MaxUnpool2d中size操作方式
Jan 03 #Python
pytorch中的卷积和池化计算方式详解
Jan 03 #Python
You might like
PHP中for循环语句的几种变型
2007/03/16 PHP
PHP 身份证号验证函数
2009/05/07 PHP
解决PHP在DOS命令行下却无法链接MySQL的技术笔记
2010/12/29 PHP
Drupal7中常用的数据库操作实例
2014/03/02 PHP
qq登录,新浪微博登录接口申请过程中遇到的问题
2014/07/22 PHP
分享php分页的功能模块
2015/06/16 PHP
PHP简单实现断点续传下载的方法
2015/09/25 PHP
PHP CURL post数据报错 failed creating formpost data
2016/10/16 PHP
基于Laravel实现的用户动态模块开发
2017/09/21 PHP
找到一点可怜的关于dojo资料,谢谢作者!
2006/12/06 Javascript
js 页面刷新location.reload和location.replace的区别小结
2009/12/24 Javascript
图片img的src不变让浏览器重新加载实现方法
2013/03/29 Javascript
JavaScript从数组中删除指定值元素的方法
2015/03/18 Javascript
jQuery动画效果图片轮播特效
2016/01/12 Javascript
jQuery使用zTree插件实现树形菜单和异步加载
2016/02/25 Javascript
结合代码图文讲解JavaScript中的作用域与作用域链
2016/07/05 Javascript
微信小程序 Record API详解及实例代码
2016/09/30 Javascript
最全的JavaScript开发工具列表 总有一款适合你
2017/06/29 Javascript
js简单遍历获取对象中的属性值的方法示例
2019/06/19 Javascript
微信小程序自定义顶部组件customHeader的示例代码
2020/06/03 Javascript
Vue实现可移动水平时间轴
2020/06/29 Javascript
[01:28:31]《加油DOTA》真人秀 第五期
2014/09/01 DOTA
介绍Python中的一些高级编程技巧
2015/04/02 Python
python脚本监控docker容器
2016/04/27 Python
Django实现网页分页功能
2019/10/31 Python
CSS3的Border-radius轻松制作圆角
2012/12/24 HTML / CSS
伦敦高达60%折扣的钻石珠宝商:Purely Diamonds
2018/06/24 全球购物
如何在.net Winform里面显示PDF文档
2012/09/11 面试题
《问银河》教学反思
2014/02/19 职场文书
教师岗位聘任书范文
2014/03/29 职场文书
文秘求职信范文
2014/04/10 职场文书
私人委托书格式
2014/09/10 职场文书
关于倡议书的范文
2015/04/29 职场文书
入党群众意见范文
2015/06/02 职场文书
宿舍卫生管理制度
2015/08/05 职场文书
Python并发编程实例教程之线程的玩法
2021/06/20 Python