在使用pytorch计算最大池化和均值池化时,需要注意函数参数中ceil_mode默认为false,也就是说计算特征图输出大小时默认向下取整的,这与caffe等框架是不一样的,因此需要根据需求设置ceil_mode的值。
在pytorch 1.0.0版本中,池化操作计算输出特征图大小默认是向下取整的,与我们平常理解向上取整不一样,如果稍有不注意会使得池化过程中出现边缘信息丢失的情况,因此使用时需要注意ceil_mode参数设置。
torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False)
参数说明如下:
Parameters:
- kernel_size – the size of the window to take a max over
- stride – the stride of the window. Default value is
kernel_size
- padding – implicit zero padding to be added on both sides
- dilation – a parameter that controls the stride of elements in the window
- return_indices – if
True
, will return the max indices along with the outputs. Useful fortorch.nn.MaxUnpool2d
later- ceil_mode – when True, will use ceil instead of floor to compute the output shape