alexandrosstergiou / SoftPool

[ICCV 2021] Code for approximated exponential maximum pooling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent behavior when stride is used

andreadps opened this issue · comments

First of all, great work with SoftPool!

When I was adapting some code to test SoftPool for the first time, I left a stride=1 on the SoftPool2d constructor and noticed this inconsistent behavior on CPU (PyTorch implementation) vs GPU (CUDA implementation).

The shape of the output is different on the two implementations. With kernel 2 and stride 1 over a 3x3 input, I expected a 2x2 output, but the CUDA implementation gives 3x3. The example below illustrates well the difference.

In [1]: import torch

In [2]: from SoftPool import SoftPool2d

In [3]: x = torch.tensor([[[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]])

In [4]: x
Out[4]: 
tensor([[[[1., 2., 3.],
          [4., 5., 6.],
          [7., 8., 9.]]]])

In [5]: SoftPool2d(kernel_size=2, stride=1)(x.cpu())
Out[5]: 
tensor([[[[4.5888, 5.5888],
          [7.5888, 8.5888]]]])

In [6]: SoftPool2d(kernel_size=2, stride=1)(x.cuda())
Out[6]: 
tensor([[[[1.0000, 1.7311, 2.7311],
          [3.8577, 4.5888, 5.5888],
          [6.8577, 7.5888, 8.5888]]]], device='cuda:0')

It looks to me that this is a bug on the way the CUDA path handles the output shape. On CUDA_SOFTPOOL2d, it does something like oH = H // stride[0] while it should do something like oH = (H - kernel_height) // stride[0] + 1. Of course some other parts of the code would need to be adapted as well.

I has found this problem.How did you solve this problem?

I found that all of softpool2d without force_inplace will not change the size of tensor

Hi @andreadps,

Thanks for this. The stride calculations should now be updated with the latest commit 70e7b3b.

Best,
Alex