Force 2d convolution to slide only along one direction

Hello,

i have a convolution layer as such:


self.conv1 = nn.Conv2d(1, nb_kernels[0], kernel_size = (2,7))

for an input of shape 2x256

and i want my 2d conv kernel to slide ONLY in the columns direction, that is to keep the dimension where it has 2 rows and slide along the columns (I would also like to keep the columns dimension but that is ok it seems with a padding of 3 in the col dir)

however i dont seem to be able to do it with the kernel size of 2 rows ?

I tried to put a stride stride=(0, 1) but that is not allowed by pytorch it seems. … I suddenly don’t understand in fact why the kernels ‘wants’ to slide along the rows direction ?

how can i do it?
(i tried padding=(1,3) → but this does not work either because it produces an output of shape [3, 256] … this confuses me … I guess the 3 comes from padding top and bottom so the kernel slides over an input of 4x256 and can therefore slide 3 times?)

P.S.
ideally i don’t want to use 1d convolutions and channels which i imagine would be a solution

sorry found out myself… too tired… of course its valid conv by default
and the 2x7 just fits in the rows direction
my mistake

Double post from here. I’m glad you have found the answer, but please stick to one account. :slight_smile: