pytorch torch.nn.AdaptiveAvgPool2d()自适应平均池化函数详解
作者:caicaiatnbu 时间:2023-12-04 02:47:49
如题:只需要给定输出特征图的大小就好,其中通道数前后不发生变化。具体如下:
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
>>>
来源:https://blog.csdn.net/caicaiatnbu/article/details/88955272
标签:pytorch,torch.nn,AdaptiveAvgPool2d,池化
0
投稿
猜你喜欢
SQL Server中修改“用户自定义表类型”问题的分析与方法
2024-01-24 01:13:58
MySQL约束超详解
2024-01-21 07:10:00
多阶段构建优化Go 程序Docker镜像
2024-02-20 13:57:40
sqlserver之datepart和datediff应用查找当天上午和下午的数据
2024-01-14 22:27:42
python多重继承实例
2022-02-06 12:12:34
Golang如何读取单行超长的文本详解
2024-05-10 13:57:21
PL/SQL Dev连接Oracle弹出空白提示框的解决方法分享
2024-01-28 03:19:05
vue 需求 data中的数据之间的调用操作
2023-07-02 16:52:03
总结python 三种常见的内存泄漏场景
2023-02-18 16:37:49
基于Python3编写一个GUI翻译器
2022-07-07 07:57:54
python实现txt文件格式转换为arff格式
2022-05-11 16:06:06
扩展Django admin的list_filter()可使用范围方法
2021-05-01 15:10:47
详解vue的diff算法原理
2023-07-02 16:49:44
图文详解如何利用PyTorch实现图像识别
2023-02-04 00:54:13
Python 保持登录状态进行接口测试的方法示例
2023-03-18 17:09:07
通俗的讲解深度学习中CUDA,cudatookit,cudnn和pytorch的关系
2023-05-02 05:07:34
Perl中的10个操作日期和时间的CPAN模块介绍
2023-07-27 10:04:41
Python基于Tkinter模块实现的弹球小游戏
2022-11-25 15:32:16
mysql实现将字符串字段转为数字排序或比大小
2024-01-16 19:59:16
Python中的sort()方法使用基础教程
2022-03-07 21:44:09