Inception Transfer learning problem

I’m trying to train my own dataset, looking at official transfer learning page on pytorch

on using inception_v3 model
model_ft = models.inception_v3(pretrained=True)

i get this huge error, can anyone help me out here?

Traceback (most recent call last):
  File "transfer_learning_tutorial.py", line 276, in <module>
    num_epochs=25)
  File "transfer_learning_tutorial.py", line 176, in train_model
    outputs = model(inputs)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torchvision/models/inception.py", line 109, in forward
    aux = self.AuxLogits(x)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torchvision/models/inception.py", line 308, in forward
    x = self.conv1(x)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torchvision/models/inception.py", line 325, in forward
    x = self.conv(x)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ffffff/.virtualenvs/LearnPytorch/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 301, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: sizes must be non-negative

what is the size of your images?
Are they of size 224x224?

Inception requires image size of 299x299. If you use this resolution, I believe there will be no problem.

256x386 is the resolution of the images I’m training on

Please check your script. I suspect you have something like:

data_transforms = {
    'train': transforms.Compose([
        transforms.RandomResizedCrop(224),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
    'val': transforms.Compose([
        transforms.Resize(256),
        transforms.CenterCrop(224),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
}

RandomResizedCrop(224) line constructs a 224x224 random crop from your image.

You need to set this for training to transforms.RandomResizedCrop(299) and for ‘val’ part
transforms.Resize(342), transforms.CenterCrop(299),

Please note that I have assumed that you have got your code from https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html .

RuntimeError: Calculated padded input size per channel: (3 x 3). Kernel size: (5 x 5). Kernel size can't be greater than actual input size at /pytorch/aten/src/THNN/generic/SpatialConvolutionMM.c:48

on changing code to

data_transforms = {
    'train': transforms.Compose([
        transforms.RandomResizedCrop(229),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
    'val': transforms.Compose([
        transforms.Resize(342),
        transforms.CenterCrop(299),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ]),
}

you have 229 instead of 299 I guess.

Yes that is correct. Sorry for the typo.