RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size can't be greater than actual input size

username: Ayush_Aditya
cooked: <p>"’<br>
RuntimeError                              Traceback (most recent call last)<br>
Cell In[10], line 15<br>
12     labels=Variable(labels.to(device))<br>
14 optimiser.zero_grad()<br>
—&gt; 15 outputs=model(inputs)<br>
16 loss=loss_function(outputs, labels)<br>
17 loss.backward()</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, **kwargs)<br>
1496 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1497 # this function, and just call forward.<br>
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1499         or _global_backward_pre_hooks or _global_backward_hooks<br>
1500         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1501     return forward_call(*args, **kwargs)<br>
1502 # Do not call functions when jit is used<br>
1503 full_backward_hooks, non_full_backward_hooks = <span class="chcklst-box fa fa-square-o fa-fw"></span>, <span class="chcklst-box fa fa-square-o fa-fw"></span></p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/inception.py:166, in Inception3.forward(self, x)<br>
164 def forward(self, x: Tensor) → InceptionOutputs:<br>
165     x = self._transform_input(x)<br>
 → 166     x, aux = self._forward(x)<br>
167     aux_defined = self.training and self.aux_logits<br>
168     if torch.jit.is_scripting():</p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/inception.py:138, in Inception3._forward(self, x)<br>
136 if self.AuxLogits is not None:<br>
137     if self.training:<br>
 → 138         aux = self.AuxLogits(x)<br>
139 # N x 768 x 17 x 17<br>
140 x = self.Mixed_7a(x)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, **kwargs)<br>
1496 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1497 # this function, and just call forward.<br>
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1499         or _global_backward_pre_hooks or _global_backward_hooks<br>
1500         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1501     return forward_call(*args, **kwargs)<br>
1502 # Do not call functions when jit is used<br>
1503 full_backward_hooks, non_full_backward_hooks = <span class="chcklst-box fa fa-square-o fa-fw"></span>, <span class="chcklst-box fa fa-square-o fa-fw"></span></p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/inception.py:386, in InceptionAux.forward(self, x)<br>
384 x = self.conv0(x)<br>
385 # N x 128 x 5 x 5<br>
 → 386 x = self.conv1(x)<br>
387 # N x 768 x 1 x 1<br>
388 # Adaptive average pooling<br>
389 x = F.adaptive_avg_pool2d(x, (1, 1))</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, **kwargs)<br>
1496 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1497 # this function, and just call forward.<br>
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1499         or _global_backward_pre_hooks or _global_backward_hooks<br>
1500         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1501     return forward_call(*args, **kwargs)<br>
1502 # Do not call functions when jit is used<br>
1503 full_backward_hooks, non_full_backward_hooks = <span class="chcklst-box fa fa-square-o fa-fw"></span>, <span class="chcklst-box fa fa-square-o fa-fw"></span></p>
<p>File /opt/conda/lib/python3.10/site-packages/torchvision/models/inception.py:405, in BasicConv2d.forward(self, x)<br>
404 def forward(self, x: Tensor) → Tensor:<br>
 → 405     x = self.conv(x)<br>
406     x = self.bn(x)<br>
407     return F.relu(x, inplace=True)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, **kwargs)<br>
1496 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1497 # this function, and just call forward.<br>
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1499         or _global_backward_pre_hooks or _global_backward_hooks<br>
1500         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1501     return forward_call(*args, **kwargs)<br>
1502 # Do not call functions when jit is used<br>
1503 full_backward_hooks, non_full_backward_hooks = <span class="chcklst-box fa fa-square-o fa-fw"></span>, <span class="chcklst-box fa fa-square-o fa-fw"></span></p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/conv.py:463, in Conv2d.forward(self, input)<br>
462 def forward(self, input: Tensor) → Tensor:<br>
 → 463     return self._conv_forward(input, self.weight, self.bias)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/conv.py:459, in Conv2d._conv_forward(self, input, weight, bias)<br>
455 if self.padding_mode != ‘zeros’:<br>
456     return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode),<br>
457                     weight, bias, self.stride,<br>
458                     _pair(0), self.dilation, self.groups)<br>
 → 459 return F.conv2d(input, weight, bias, self.stride,<br>
460                 self.padding, self.dilation, self.groups)</p>
<p>RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size can’t be greater than actual input size<br>
‘’’<br>
Code<br>
from torchvision import models<br>
model = models.inception_v3(pretrained=True)<br>
model.fc = nn.Linear(512, 10)<br>
if torch.cuda.device_count() &gt; 1:<br>
print(“Let’s use”, torch.cuda.device_count(), “GPUs!”)<br>
model = nn.DataParallel(model)<br>
model = model.to(device)</p>

username: ptrblck
cooked: <p>Increase the spatial size of the input to make sure the activations are not smaller than kernels as given in the error message.</p>

username: Ayush_Aditya
cooked: <p>its an audio analysis how does one do this?</p>

username: ptrblck
cooked: <p>I guess you could use <code>torchaudio.transforms.TimeStretch</code> or any other transformation increasing the temporal size.</p>