Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VolumetricAveragePooling gives error when Kernel Size is equal to the Input Feature Map(s)'s size #536

Closed
rudrapoudel opened this issue Dec 15, 2015 · 9 comments

Comments

@rudrapoudel
Copy link

Hi there,

When I am using Kernel Size is equal to the Input Feature Map(s)'s size, I am getting following error,

...ch/install/share/lua/5.1/nn/VolumetricAveragePooling.lua:20: bad argument #2 to 'VolumetricAveragePooling_updateOutput' (input image smaller than kernel size)

I think we need to check > rather than >= in the following kind of argcheck ???

luaL_argcheck(L, input->size[dimw] >= kW && input->size[dimh] >= kH &&
input->size[dimt] >= kT, 2,
"input image smaller than kernel size");

Here is the code to check the things quickly,

require 'torch'
require 'nn'
torch.setdefaulttensortype('torch.FloatTensor')

local nn_backend = nn
if false then
    require 'cudnn'
    nn_backend = cudnn
    torch.setdefaulttensortype('torch.CudaTensor')
end

if false then
    vap = nn_backend.VolumetricAveragePooling(2, 2, 2,
                                              2, 2, 2)
else
    vap = nn_backend.VolumetricAveragePooling(5, 7, 5,
                                              5, 7, 5)
end

inputs = torch.rand(8, 16, 5, 7, 5)  -- batch size, no. of feature maps, t, h, w
outputs = vap:forward(inputs)
print(outputs:size())
@kmul00
Copy link
Contributor

kmul00 commented Dec 15, 2015

I think the problem lies in the different order the dimenisons are parsed by the lua and the underlying c code, respectively.

In VolumetricAveragePooling.lua the input is parsed as kT, kW, kH (here).

Whereas the VolumetricAveragePooling.c parses the kernel indices to be dimt = 1, dimh = 2, dimw = 3 (here). The order of height and width are getting exchanged, and hence the mismatch.

In fact, on further inspection, I found that this is the case with all the _Volumetric_ modules.

@soumith and @fmassa , can either of you please confirm regarding this.
If true, then it needs to be changed. I can send fix for it.

@kmul00
Copy link
Contributor

kmul00 commented Dec 15, 2015

The easiest fix could be to change the input format of the _Volumetric_ modules (the lua files) from (kT, kW, kH) to (kT, kH, kW).

Then the underlying c codes as well as the cuda codes (here) for all the modules need not be changed.

@soumith
Copy link
Member

soumith commented Dec 16, 2015

@kmul00 i dont think that's the issue. They are correctly parsed here: https://github.com/torch/nn/blob/master/generic/VolumetricAveragePooling.c#L46-L51

@kmul00
Copy link
Contributor

kmul00 commented Dec 16, 2015

@soumith Yeah, that part is correct. The input format is (kT, kW, kH), and they are parsed correctly as well, like you pointed out. But then it assigns,

int dimt = 1;
int dimh = 2;
int dimw = 3;

So, when it performs input->size[dimw] >= kW, it is basically comparing the third diemension of the input (since, dimw = 3) with the second dimension of the kernel (kW). I think that's where the discrepency lies.

And similarly for input->size[dimh] >= kH.

@soumith
Copy link
Member

soumith commented Dec 16, 2015

dimw = 3 is correct. The ordering in the constructors is a bit legacy, and is ordered kT, kW, kH. But the inputs / outputs are ordered iT x iH x iW.

@kmul00
Copy link
Contributor

kmul00 commented Dec 16, 2015

I think that's why it is creating a problem. Most of the times we keep the height and width dimenion same, hence it doesn't cause any problem.

For example, if I use

input = torch.Tensor(8, 16, 5, 7, 5)
model = nn.Sequential()
model:add(nn.VolumetricAveragePooling(5, 7, 5)

it throws an error as pointed out in the issue. But instead, if I use

model:add(nn.VolumetricAveragePooling(5, 5, 7)

it executes without any error. Of course the results are erroneous, but the dimesnions doesn't cause any problem.

@soumith
Copy link
Member

soumith commented Dec 16, 2015

The example itself is wrong. Inputs should be:

inputs = torch.rand(8, 16, 5, 5, 7) -- t, h, w

because the constructor is:
(T, W, H, ...)

@soumith
Copy link
Member

soumith commented Dec 16, 2015

@soumith soumith closed this as completed Dec 16, 2015
@kmul00
Copy link
Contributor

kmul00 commented Dec 16, 2015

Oh, now I see. This made it clear. The orderings of the kernel and input are altogether different. Sorry for the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants