How to perform sum pooling in PyTorch. Specifically, if we have input (N, C, W_in, H_in)
and want output (N, C, W_out, H_out)
using a particular kernel_size
and stride
just like nn.Maxpool2d
?
You could use torch.nn.AvgPool1d
(or torch.nn.AvgPool2d
, torch.nn.AvgPool3d
) which are performing mean pooling - proportional to sum pooling. If you really want the summed values, you could multiply the averaged output by the pooling surface.
Do you mean, first I perform Avgpool2d and than multiply the resulting tensor by 4 if my kernel size is 4 ?
Yes, average pooling first, then multiply back the results by
4 * 4 = 16
ifkernel_size=4
(as it means the average is computed over a region of4 * 4 = 16
elements).