#%%
import torch
from torch import nn
#%% 最大值池化
arry = torch.arange(16,dtype=torch.float32).view([1,1,4,4])
print(arry)
maxp = nn.MaxPool2d(kernel_size=2) #kernel_size=2,stride=kernel_size
Avgp = nn.AvgPool2d(kernel_size=2) #kernel_size=2,stride=kernel_size
print(maxp(arry))
print(Avgp(arry))
tensor([[[[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[12., 13., 14., 15.]]]])
最大值池化: tensor([[[[ 5., 7.],
[13., 15.]]]])
均值池化 : tensor([[[[ 2.5000, 4.5000],
[10.5000, 12.5000]]]])