Hello everyone !
I’m trying to use a pretrained model (the Inception_v3) from the Pytorch library. But I have a strange mistake with the transfert…
Here my code :
model = models.inception_v3(pretrained=True)
model.aux_logits = False
for param in model.parameters():
param.requires_grad = False
num_ftrs = model.fc.in_features
model.fc = nn.Linear(num_ftrs, 12)
if use_gpu: model = model.cuda()
optimizer = torch.optim.SGD(model.fc.parameters(), lr=0.001, momentum=0.9)
criterion = torch.nn.CrossEntropyLoss()
exp_lr_scheduler = lr_scheduler.StepLR(optimizer, step_size=7, gamma=0.1)
model = train_model(model, dataloaders, datasets_sizes, criterion,
optimizer, exp_lr_scheduler, num_epochs=25)
And here the error :
<ipython-input-10-de7ae08d1d1a> in train_model(model, dataloaders, dataset_size, criterion, optimizer, scheduler, num_epochs)
28
29 # Forward
---> 30 outputs = model(inputs)
31 _, predictions = torch.max(outputs.data, 1)
32 loss = criterion(outputs, labels)
~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
355 result = self._slow_forward(*input, **kwargs)
356 else:
--> 357 result = self.forward(*input, **kwargs)
358 for hook in self._forward_hooks.values():
359 hook_result = hook(self, input, result)
~/anaconda3/lib/python3.6/site-packages/torchvision-0.2.0-py3.6.egg/torchvision/models/inception.py in forward(self, x)
115 x = self.Mixed_7c(x)
116 # 8 x 8 x 2048
--> 117 x = F.avg_pool2d(x, kernel_size=8)
118 # 1 x 1 x 2048
119 x = F.dropout(x, training=self.training)
RuntimeError: Given input size: (2048x5x5). Calculated output size: (2048x0x0). Output size is too small at /opt/conda/conda-bld/pytorch-cpu_1518282373170/work/torch/lib/THNN/generic/SpatialAveragePooling.c:64
Anybody got any ideas?
(The train_model function comes from the Pytorch Transfert Learning Tutorial)
Thank you in advance !