Hi, I ran into a similar error while playing around with the [https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html 10](Transfer Learning Tutorial). The reason for posting this is that the error message doesn’t seem to be related to the error itself, at least the listed values that are named in it do not make sense to me.
Error itself was caused by an incorrect tensor shape as input to the model.
For this particular case I found a workaround, though maybe reporting it may be helpful. Below is what I did and the error. I’m using pytorch v0.4.1.

After training the model I’d like to feed it with a single image. Therefore I define a single image path and a custom data transformer and transform the image to its tensor equivalent.
When inputting this tensor to the model ([3, 224, 224]), the batch size dimension is missing, giving me the error (bottom of the post).
I did a workaround by ‘unsqueezing’ the tensor to a correct shape ([1, 3, 224, 224).
Inputting the unsqueezed tensor gives a prediction result as expected.

from PIL import Image

# Get single image
img_path = "/hymenoptera_data/train/ants/0013035.jpg"
img = Image.open(open(img_path, 'rb'))

# Define transformation
composed = transforms.Compose([
    transforms.Resize(256),
    transforms.CenterCrop(224),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

img_trfd = composed(img)
img_trfd.size()              # output: torch.Size([3, 224, 224])
model_tf(img_trfd)           # GIVES ERROR AS BELOW

img_trfd_unsq = img_trfd.unsqueeze(0)
img_trfd_unsq.size()         # output: torch.Size([1, 3, 224, 224])
model_ft(img_trfd_unsq)      # Predicting results correctly

Error at incorrect input tensor size:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/bloks/Projects/Sentriq/sentriq_venv/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/bloks/Projects/Sentriq/sentriq_venv/lib/python3.5/site-packages/torchvision/models/resnet.py", line 139, in forward
    x = self.conv1(x)
  File "/home/bloks/Projects/Sentriq/sentriq_venv/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/bloks/Projects/Sentriq/sentriq_venv/lib/python3.5/site-packages/torch/nn/modules/conv.py", line 301, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [64, 3, 7, 7], but got input of size [3, 224, 224] instead