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