How to finetune pretrained inception_v3 model with PyTorch?

I use this script to finetune inception_v3 model on a custom dataset. The script already supports AlexNet and VGGNet. However, when finetune with pretrained inception_v3 model, there is an error:

python main.py -a inception_v3 -b 16 --lr 0.01 --pretrained data
=> using pre-trained model 'inception_v3’
Traceback (most recent call last):
File “main.py”, line 352, in
main()
File “main.py”, line 194, in main
train(train_loader, model, criterion, optimizer, epoch)
File “main.py”, line 231, in train
output = model(input_var)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/parallel/data_parallel.py”, line 59, in forward
return self.module(*inputs[0], **kwargs[0])
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “main.py”, line 104, in forward
f = self.features(x)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/container.py”, line 64, in forward
input = module(input)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/torchvision/models/inception.py”, line 311, in forward
x = self.fc(x)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/linear.py”, line 54, in forward
return self._backend.Linear()(input, self.weight, self.bias)
File "/usr/local/lib/python2.7/dist-packages/torch/nn/functions/linear.py", line 10, in forward
output.addmm
(0, 1, input, weight.t())
RuntimeError: size mismatch at /b/wheel/pytorch-src/torch/lib/THC/generic/THCTensorMathBlas.cu:243

Has anyone finetuned inception_v3 successfully?

1 Like

Here’s a recent discussion.

Also, someone just released this, which finetunes any network from the model zoo.

1 Like

@achaiah Thanks for the resource!

@panovr have you identified what was causing the error? Am running into the same error message using the pretrained VGG16.

ah - in my case it was just a silly error with giving in images in incorrect size…