什么是池化
就是降低图像分辨率,比如一个3x3的池化操作(如下),会每3x3取其中的最大值
相关代码import torch input = torch.tensor([[1,2,0,3,1], [0,1,2,3,1], [1,2,1,0,0], [5,2,3,1,1], [2,1,0,1,1]], dtype=torch.float32) #(batch_size, 通道数,宽,高),-1是自适应的意思 input = torch.reshape(input, (-1,1,5,5)) print(input.shape) class Tudui(torch.nn.Module): def __init__(self): super(Tudui,self).__init__() self.maxpool=torch.nn.MaxPool2d(kernel_size=3,ceil_mode=True) def forward(self,x): x = self.maxpool(x) return x tudui = Tudui() output = tudui(input) print(output)
运行结果:
如果我们将ceil_mode=False
运行结果:
可以看出ceil_mode的作用就是,是否保留不完整的3x3区域
可选参数stride,padding和convolution(卷积)相同