Helias / Car-Model-Recognition

Car Model Recognition project
75 stars 19 forks source link

size mismatch #2

Closed game-sys closed 5 years ago

game-sys commented 5 years ago

I have tried several solutions available but nothing worked for me.. Could you please help to resolve this issue?

RuntimeError: Error(s) in loading state_dict for ResNet: size mismatch for fc.weight: copying a param with shape torch.Size([1000, 2048]) from checkpoint, the shape in current model is torch.Size([3, 2048]). size mismatch for fc.bias: copying a param with shape torch.Size([1000]) from checkpoint, the shape in current model is torch.Size([3]).

Helias commented 5 years ago

Hey, probably you are using an input with different size that the ResNet expect, try to handle the input that you're giving into the neural network is the correct input.

Anyway, soon I will update the documentation about this project.

AqsaHassan commented 5 years ago

Unfortunately I'm also facing the same issue.. I tried to change strict=false def load_state_dict(self, state_dict, strict=True): in module.py, but still it's strict to exact match. Also I have tried by changing num_classes=3 from num classes=100 in class ResNet(nn.Module):

def __init__(self, block, layers, num_classes=1000, zero_init_residual=False,
             groups=1, width_per_group=64, replace_stride_with_dilation=None,
             norm_layer=None):

Still getting the same issue. Although, Its running well with 1000 classes in dataset.

Helias commented 5 years ago

Give me a couple of days and I will update the documentation and add a section about troubleshooting, promise 😉.

AqsaHassan commented 5 years ago

Okay... I'll be waiting. Thanks

Helias commented 5 years ago

Project and documentation updated, so download the new source of the project.

To solve this issue you need to set pretrained=false at this line and now you can run the training (it will take a lot of time).

resnet152_model = resnet.resnet152(pretrained=False, **classes)

P.S. = leave a star in the repository if this project helped you 😉

Helias commented 5 years ago

If you meet any errors write me here, if you don't get any error I will close this issue.