RuntimeError: Calculated padded input size per channel: (3). Kernel size: (20). Kernel size can't be greater than actual input size

lilabard: <p>Hi,</p>
<p>I’m so new at Pytorch, and I’m trying to convert my Keras model into Pytorch one. In Keras, I can use the <code>kernel_size = 20</code> with the same data and I worked well. However, when I define as 20 with the same data and architectire in Pytorch, I got the following error. I can’t really understand the main reason for this error since It was working well in Keras.<br>
I’d be appreciated If you could make me understand the issue and solution.</p>
<pre><code class="lang-auto">RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-25-74505e66d6bf&gt; in &lt;module&gt;
     17 
     18         # Forward pass
---&gt; 19         outputs = model(dataX.float())
     20         loss = criterion(outputs, labels)
     21 

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--&gt; 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

&lt;ipython-input-19-6d0943e3b0de&gt; in forward(self, x)
     28         x = self.maxpool1(x)
     29         print("x", x.size())
---&gt; 30         x = self.cnn3(x)
     31         print("cnn3", x.size())
     32         x = self.act3(x)

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--&gt; 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

~\Anaconda3\lib\site-packages\torch\nn\modules\conv.py in forward(self, input)
    261 
    262     def forward(self, input: Tensor) -&gt; Tensor:
--&gt; 263         return self._conv_forward(input, self.weight, self.bias)
    264 
    265 

~\Anaconda3\lib\site-packages\torch\nn\modules\conv.py in _conv_forward(self, input, weight, bias)
    257                             weight, bias, self.stride,
    258                             _single(0), self.dilation, self.groups)
--&gt; 259         return F.conv1d(input, weight, bias, self.stride,
    260                         self.padding, self.dilation, self.groups)
    261 

RuntimeError: Calculated padded input size per channel: (3). Kernel size: (20). Kernel size can't be greater than actual input size```</code></pre>

ptrblck: <p>Could you post the model definition in Keras as well as PyTorch?<br>
I guess you might use different conv settings, e.g. using <code>padding='same'</code> in Keras while not using any padding in PyTorch, which would yield different output activation shapes.</p>

lilabard: <p>I’m sorry, I can’t post the model definition, unfortunately (my company policies). I used padding <code>default</code> which is <code>same</code>, but I also defined my <code>padding=1</code> in everywhere which is the equivalent of the Keras model I wrote. As far as I know, Keras is padding with the required amount of zeros for the filter, yet this is also equivalent to apply convolution on a bunch of zeros. Therefore, I updated the model parameters as Pytorch asks. So, problem solved. Thanks anyway.</p>