torch.nn.functional.Conv3d groups problem

Hi everyone!

Since I use custom weights in my network I often rely on torch.nn.functional.conv3d rather than torch.nn.Conv3d.
Today I wanted to start to experiment with different group sizes, however there seems to be a bug in the current pytorch 0.2 version?
Following code snippet for example doesn’t work for me:

import torch
myX = torch.autograd.Variable(torch.randn(1,2,5,5,5))
myW = torch.autograd.Variable(torch.randn(4, 2, 3, 3, 3))
y = torch.nn.functional.conv3d(myX, myW, groups=2)

The resulting error:

in conv3d

return f(input, weight, bias)
RuntimeError: size mismatch, m1: [2 x 54], m2: [27 x 27] at /opt/conda/conda-bld/pytorch_1502008109146/work/torch/lib/TH/generic/THTensorMath.c:1293

If I use

c3d = torch.nn.Conv3d(2,4,3,groups=2)
y = c3d(myX)

everything works fine. Nevertheless I would like to be able to use the nn.functional.conv3d interface.
Does anyone face the same problem? Is this a bug for which I should open an issue on github?

Greetings!

this definitely seems like a bug. if you would open an issue at https://github.com/pytorch/pytorch/issues i’ll take care of it right away.

Hi,
what is the difference between conv3d and conv2d?

Can you give me some suggestions?

Thank you so much.

conv3d is for convolution in 3D space (depth x height x width) like videos, 2D is for images

I looked into this more closely. This is actually because you gave myW of incorrect size.

If groups=2, then myW has to be of shape (4, 1, 3, 3, 3), i.e. (outputChannels, inputChannels // groups, kT, kH, kW)