The default image size in the tutorial is 224x224,however,I went to try some other size(such as 225 or 256) in this tutorial.So I only modified the following section:
img_size=225
data_transforms = {
'train': transforms.Compose([
#transforms.RandomResizedCrop(224),
transforms.Resize((img_size,img_size)),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
]),
'val': transforms.Compose([
transforms.Resize((img_size,img_size)),
#transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
]),
}
But when running this demo again,I got these error message:
Traceback (most recent call last):
File "C:/Users/Javis/PycharmProjects/pytorch_demo/transfer_learning_tutorial.py", line 289, in <module>
num_epochs=25)
File "C:/Users/Javis/PycharmProjects/pytorch_demo/transfer_learning_tutorial.py", line 187, in train_model
outputs = model(inputs)
File "C:\Users\Javis\AppData\Local\Continuum\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 357, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\Javis\AppData\Local\Continuum\Anaconda3\lib\site-packages\torchvision\models\resnet.py", line 151, in forward
x = self.fc(x)
File "C:\Users\Javis\AppData\Local\Continuum\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 357, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\Javis\AppData\Local\Continuum\Anaconda3\lib\site-packages\torch\nn\modules\linear.py", line 55, in forward
return F.linear(input, self.weight, self.bias)
File "C:\Users\Javis\AppData\Local\Continuum\Anaconda3\lib\site-packages\torch\nn\functional.py", line 835, in linear
return torch.addmm(bias, input, weight.t())
RuntimeError: size mismatch, m1: [4 x 2048], m2: [512 x 2] at c:\miniconda2\conda-bld\pytorch-cpu_1519449358620\work\torch\lib\th\generic/THTensorMath.c:1434
It 's very strange when I reset the img_size to 224 or less than 224,It became normal again. why I can not get a size more than 224 in this tutorual ?
Any hellp will be very appreciated !