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模块学习 filecmp 文件比较
Aug 27 Python
在Python的Flask框架中使用日期和时间的教程
Apr 21 Python
Python使用openpyxl读写excel文件的方法
Jun 30 Python
Python实现判断一个字符串是否包含子串的方法总结
Nov 21 Python
Django框架教程之正则表达式URL误区详解
Jan 28 Python
python购物车程序简单代码
Apr 18 Python
NLTK 3.2.4 环境搭建教程
Sep 19 Python
python之Flask实现简单登录功能的示例代码
Dec 24 Python
基于python实现的百度新歌榜、热歌榜下载器(附代码)
Aug 05 Python
python SocketServer源码深入解读
Sep 17 Python
Python 如何对文件目录操作
Jul 10 Python
vscode+PyQt5安装详解步骤
Aug 12 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
论建造顺序的重要性
2020/03/04 星际争霸
Search File Contents PHP 搜索目录文本内容的代码
2010/02/21 PHP
php学习之流程控制实现代码
2011/06/09 PHP
鸡肋的PHP单例模式应用详解
2013/06/03 PHP
深入PHP异步执行的详解
2013/06/03 PHP
ThinkPHP3.1新特性之对页面压缩输出的支持
2014/06/19 PHP
php实现基于微信公众平台开发SDK(demo)扩展的方法
2014/12/22 PHP
php中静态类与静态变量用法的区别分析
2015/01/15 PHP
javascript实现仿银行密码输入框效果的代码
2007/12/13 Javascript
Extjs中ComboBox加载并赋初值的实现方法
2012/03/22 Javascript
JavaScript通过元素的ID和name设置样式
2014/07/08 Javascript
前端jquery部分很精彩
2016/05/03 Javascript
JavaScript根据CSS的Media Queries来判断浏览设备的方法
2016/05/10 Javascript
BootStrapTable 单选及取值的实现方法
2017/01/10 Javascript
bootstrap table分页模板和获取表中的ID方法
2017/01/10 Javascript
JavaScript函数参数的传递方式详解
2017/03/06 Javascript
简单谈谈原生js的math对象
2017/06/27 Javascript
最基础的vue.js双向绑定操作
2017/08/23 Javascript
React Native预设占位placeholder的使用
2017/09/28 Javascript
详解Vue前端生产环境发布配置实战篇
2019/05/07 Javascript
JavaScript实现好看的跟随彩色气泡效果
2020/02/06 Javascript
python发送arp欺骗攻击代码分析
2014/01/16 Python
详细解读Python的web.py框架下的application.py模块
2015/05/02 Python
sublime text 3配置使用python操作方法
2017/06/11 Python
Python基于datetime或time模块分别获取当前时间戳的方法实例
2019/02/19 Python
python dumps和loads区别详解
2020/02/04 Python
如何用Python编写一个电子考勤系统
2021/02/08 Python
日本民宿预约平台:STAY JAPAN
2017/07/01 全球购物
英国网上购买肉类网站:Great British Meat
2018/10/17 全球购物
小学班主任评语大全
2014/04/23 职场文书
支行行长竞聘演讲稿
2014/05/15 职场文书
后勤工作个人总结
2015/02/28 职场文书
实习证明模板
2015/06/16 职场文书
靠谱的活动总结
2019/04/16 职场文书
nginx安装以及配置的详细过程记录
2021/09/15 Servers
Golang 并发编程 SingleFlight模式
2022/04/26 Golang