... RuntimeError: mat1 dim 1 must match mat2 dim 0

Hi there, so I am currently trying to learn about Few-Shot Learning, and I was running this code as one of the baselines for my project. I encountered the error when I was trying to change the backbone_model from “conv-4” to ResNet.

Here’s the error mentioned:
Traceback (most recent call last):
File “pretrain.py”, line 113, in
logits = model(data)
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 889, in _call_impl
result = self.forward(*input, **kwargs)
File “/opt/conda/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py”, line 165, in forward
return self.module(*inputs[0], **kwargs[0])
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 889, in _call_impl
result = self.forward(*input, **kwargs)
File “/home/jovyan/DiffKendall/Models/models/DiffKendall.py”, line 75, in forward
return self.fc(x)
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 889, in _call_impl
result = self.forward(*input, **kwargs)
File “/opt/conda/lib/python3.8/site-packages/torch/nn/modules/linear.py”, line 94, in forward
return F.linear(input, self.weight, self.bias)
File “/opt/conda/lib/python3.8/site-packages/torch/nn/functional.py”, line 1753, in linear
return torch._C._nn.linear(input, weight, bias)

I checked that my input is (128, 3, 84, 84) but I still cannot figure out what is wrong with the code. Any help is appreciated🙏🏼

I’ve also provided the link to the whole code here:

The issue is raised in self.fc so you might need to check the activation shape and make sure the feature dimension matches the in_features in the linear layer.