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 09 Python
详解python 发送邮件实例代码
Dec 22 Python
Python操作MongoDB数据库的方法示例
Jan 04 Python
详解python函数传参是传值还是传引用
Jan 16 Python
十行代码使用Python写一个USB病毒
Jun 21 Python
python日期相关操作实例小结
Jun 24 Python
浅谈Python中函数的定义及其调用方法
Jul 19 Python
Django之使用内置函数和celery发邮件的方法示例
Sep 16 Python
pandas中的ExcelWriter和ExcelFile的实现方法
Apr 24 Python
python 读取、写入txt文件的示例
Sep 27 Python
python使用正则表达式匹配txt特定字符串(有换行)
Dec 09 Python
Python实现科学占卜 让视频自动打码
Apr 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
PHPMailer安装方法及简单实例
2008/11/25 PHP
PHP文件操作详解
2016/12/30 PHP
php curl上传、下载、https登陆实现代码
2017/07/23 PHP
详解php中生成标准uuid(guid)的方法
2019/04/28 PHP
jquery.validate分组验证代码
2011/03/17 Javascript
jQuery图片播放8款精美插件分享
2013/02/17 Javascript
html+javascript实现可拖动可提交的弹出层对话框效果
2013/08/05 Javascript
jquery获取元素索引值index()示例
2014/02/13 Javascript
javascript 控制input只允许输入的各种指定内容
2014/06/19 Javascript
常用的jQuery前端技巧收集
2014/12/24 Javascript
jQuery表单域属性过滤器用法分析
2015/02/10 Javascript
Bootstrap入门书籍之(三)栅格系统
2016/02/17 Javascript
原生javascript实现分享到朋友圈功能 支持ios和android
2016/05/11 Javascript
使用jQuery实现WordPress中的Ctrl+Enter和@评论回复
2016/05/21 Javascript
文本框只能输入数字的js代码(含小数点)
2016/07/10 Javascript
Vuejs第十篇之vuejs父子组件通信
2016/09/06 Javascript
详解VUE的状态控制与延时加载刷新
2017/03/27 Javascript
Vue 实用分页paging实例代码
2017/04/12 Javascript
PHP魔术方法__ISSET、__UNSET使用实例
2014/11/25 Python
python检测某个变量是否有定义的方法
2015/05/20 Python
python实现微信小程序自动回复
2018/09/10 Python
pygame实现俄罗斯方块游戏(对战篇1)
2019/10/29 Python
python使用HTMLTestRunner导出饼图分析报告的方法
2019/12/30 Python
Python私有属性私有方法应用实例解析
2020/09/15 Python
通过css3的filter滤镜改变png图片的颜色的示例代码
2020/05/06 HTML / CSS
Skyscanner台湾:全球知名的旅行比价引擎
2018/07/01 全球购物
Java语言程序设计测试题选择题部分
2014/04/03 面试题
社会实践活动总结范文
2014/07/03 职场文书
秋季运动会广播稿(30篇)
2014/09/13 职场文书
祖国在我心中演讲稿(小学生)
2014/09/23 职场文书
离婚协议书范本(通用篇)
2014/11/30 职场文书
酒店服务员岗位职责
2015/02/09 职场文书
导盲犬小Q观后感
2015/06/11 职场文书
聘任合同书
2015/09/21 职场文书
详解Apache SkyWalking 告警配置指南
2021/04/22 Servers
PyTorch 如何设置随机数种子使结果可复现
2021/05/12 Python