MaxPool2d()
常用参数:
kernel_size 核大小
stride 窗口滑动步长
padding 增加的边距
更多参数见官网
输出尺寸大小计算公式
代码演示
import torch
MP = torch.nn.MaxPool2d(3,stride=2)
input = torch.randn(1, 64, 8, 9)
print(MP(input).size())
AdaptiveAvgPool2d()
参数:形式为H x W的图像的目标输出尺寸。对于正方形图像H x H,可以是元组(H,W)或单个H。H和W可以是“int”,也可以是“None”,这意味着大小将与输入相同。
区别:在MaxPool2d
做出的改进是参数只要输入需要输出的尺寸大小就行
代码演示:
import torch
# target output size of 5x5
m0 = torch.nn.AdaptiveMaxPool2d((5,5))
# target output size of 6x6
m1 = torch.nn.AdaptiveMaxPool2d((6,6))
# target output size of 7x7
m2 = torch.nn.AdaptiveMaxPool2d((7,7))
input = torch.randn(1, 64, 8, 9)
print(m0(input).size(),m1(input).size(),m2(input).size())
分析:很清楚看到当我们输入的参数大小就我们输出的尺寸大小,这很方便。
扩展:对于AdaptiveAvgPool3d
只是在AdaptiveAvgPool2d
的基础上又增加了一维的输入有原来H * W
变成 D * H * W