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

resnext 50 on imagenet load pretrain model failed #18

Closed
yaoing opened this issue Jun 1, 2018 · 3 comments
Closed

resnext 50 on imagenet load pretrain model failed #18

yaoing opened this issue Jun 1, 2018 · 3 comments

Comments

@yaoing
Copy link

yaoing commented Jun 1, 2018

i try to modify resnext50 function to:

def resnext50(baseWidth, cardinality,pretrained=True):
    """
    Construct ResNeXt-50.
    """
    model = ResNeXt(baseWidth, cardinality, [3, 4, 6, 3], 1000)
    if pretrained:
        model.load_state_dict(torch.load('model_best.pth.tar')['state_dict'])
        print('loaded model')

    return model

the model_best.pth.tar file download from the link of readme.md

and some errors raised when i run:

Traceback (most recent call last):
  File "imagenet.py", line 348, in <module>
    main()
  File "imagenet.py", line 152, in main
    cardinality=args.cardinality,
  File "/media/amax/xgessd/yao/pytorch-classification/models/imagenet/resnext.py", line 160, in resnext50
    model.load_state_dict(torch.load('ResNext50_checkpoint_best.pth.tar')['state_dict'])
  File "/home/amax/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 721, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for ResNeXt:
	Missing key(s) in state_dict: "conv1.weight", "bn1.weight", "bn1.bias", "bn1.running_mean", "bn1.running_var", "lay........
@yaoing
Copy link
Author

yaoing commented Jun 1, 2018

求助~

@bearpaw
Copy link
Owner

bearpaw commented Jun 1, 2018

Please refer to the --resume parameter about loading a pretrained model:
https://github.com/bearpaw/pytorch-classification/blob/master/imagenet.py#L171-L181

@yaoing
Copy link
Author

yaoing commented Jun 1, 2018

@bearpaw OK,solved !

@bearpaw bearpaw closed this as completed Jun 7, 2018
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

2 participants