Pytorch Equivalent to Keras Conv2d Layer

I Have a conv2d layer in keras with the input shape from input_1 (InputLayer) [(None, 100, 40, 1)]

   input_lmd = Input(shape=(T, NF, 1))

    # build the convolutional block
    conv_first1 = Conv2D(32, (1, 2), strides=(1, 2))(input_lmd)

I’m trying to do the equivalent in Pytorch with something like

 self.conv1 = nn.Conv2d(100, 32, (1, 2), stride=(1, 2))

But i’m getting the error

*** RuntimeError: Calculated padded input size per channel: (40 x 1). Kernel size: (1 x 2). Kernel size can’t be greater than actual input size

The width of your input is 1, but your kernel has width 2. That will not work. You probably want to make your kernel and stride (2, 1) or switch H and W in your input.

1 Like

Turns out keras/tensorflow use channel last so I needed to reshape the input tensor to account for this