Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in loading resnet model #25

Open
sparshgarg23 opened this issue Mar 10, 2022 · 2 comments
Open

Error in loading resnet model #25

sparshgarg23 opened this issue Mar 10, 2022 · 2 comments

Comments

@sparshgarg23
Copy link

I am using model_zoo.load_url to load resnet50 model,however when I use the downloaded model,I end up recieivng the error message as shown below

loading annotations into memory...
Done (t=18.10s)
creating index...
index created!
INFO====>check annos, filtering invalid data......
Traceback (most recent call last):
  File "train_coco.py", line 39, in <module>
    model=FCOSDetector(mode="training").cuda()
  File "/content/fcos/model/fcos.py", line 217, in __init__
    self.fcos_body=FCOS(config=config)
  File "/content/fcos/model/fcos.py", line 22, in __init__
    self.backbone=resnet34(pretrained=True,if_include_top=False)
  File "/content/fcos/model/backbone/resnet.py", line 194, in resnet34
    model.load_state_dict(model_zoo.load_url(model_urls['resnet34']))
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1483, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for ResNet:
	Unexpected key(s) in state_dict: "fc.weight", "fc.bias"

Would it be possible for you to share the resnet50.pth file,if not then any suggestions on what can be done to resolve this.

@chaowentao
Copy link

将strict的值设为False即可

def _resnet(arch, block, layers, pretrained, progress, **kwargs):
  model = ResNet(block, layers, **kwargs)#自己定义的model
  if pretrained:
    state_dict = load_state_dict_from_url(model_urls[arch], progress=progress)#预训练的model
    model.load_state_dict(state_dict, strict=False)
   
    """如果是加载本地下载好的预训练模型,就用torch.load(),再把strict设为False
    model.load_state_dict(torch.load("./resnet50-19c8e357.pth"),strict=False)
    """
  return model

@zhenghao977
Copy link
Owner

zhenghao977 commented Mar 27, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants