视频地址神经网络-最大池化的使用_哔哩哔哩_bilibili
kernel_size (Union[int, Tuple[int, int]]) –要占用的最大窗口的大小 |
stride (Union[int, Tuple[int, int]]) –窗户的步长。默认是kernel_size |
padding (Union[int, Tuple[int, int]]) –隐式负无穷大填充将被添加到两边 |
dilation (Union[int, Tuple[int, int]]) –控制窗口中元素步幅的参数 |
return_indices (bool) –如果为True,将返回最大索引以及输出。有用的火炬。nn.MaxUnpool2d之后 |
ceil_mode (bool) –当为True时,将使用ceil而不是floor来计算输出形状 |
python">import torch
from torch import nn
from torch.nn import MaxPool2dinput = 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)input = torch.reshape(input, (-1, 1, 5, 5)) #-1让程序自己选择合适的batch sizeclass Tudui(nn.Module):def __init__(self):super(Tudui, self).__init__()self.maxpool1 = MaxPool2d(kernel_size=3, ceil_mode=True)def forward(self, input):output = self.maxpool1(input)return outputtudui = Tudui()
output = tudui(input)
print(output)
# tensor([[[[2., 3.],
# [5., 1.]]]])