Torch.nn.functional.conv2d on 5D vectors?

I understand that the intended usage of the conv2d is to make it act on 4D input vectors and kernels, the docs never specifically stated that you can’t use it with higher dimensions.

I tried, for fun, testing what does conv2d does for 5D vectors. First I tried to try the simplest no-op case, that should just return multi-dimensional vector of size 1:

>>> import torch
>>> torch.nn.functional.conv2d(torch.ones(1,1,1,1), torch.ones(1,1,1,1))
tensor([[[[1.]]]])
>>> torch.nn.functional.conv2d(torch.ones(1,1,1,1,1), torch.ones(1,1,1,1,1))
RuntimeError: expected stride to be a single integer value or a list of 3 values to match the convolution dimensions, but got stride=[1, 1]

I’ve got the error message asking me to put the correct (three) dimensions on the stride, padding, dilation and… output_padding.

>>> torch.nn.functional.conv2d(torch.ones(1,1,1,1,1), torch.ones(1,1,1,1,1), stride=(1,1,1), padding=(0,0,0), dilation=(1,1,1), output_padding=(0,0,0))
TypeError: conv2d() got an unexpected keyword argument 'output_padding'

Is it the pytorch bug? Or did I miss the limitation that the conv2d can only act on 4D vectors - if so, why the code does not check for it assert len(input.shape)==4 when it already checks for so many errors?

Hi,

Yes, conv2d can only work with 4D inputs. You can use conv3d to work with 5D.
And we are definitely missing some error checking here to make sure the user is not providing wrong arguments. Could you open an issue on github about that please?