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

AttributeError: 'Namespace' object has no attribute 'num_classes' / Missing and Unexpected keys in state_dict #2

Open
ge97qir opened this issue Jan 14, 2021 · 1 comment

Comments

@ge97qir
Copy link

ge97qir commented Jan 14, 2021

I assume I have all the correct dependencies since I had errors before and resolved them by installing cuda 9.0 with gcc-5 and g++-5, but now I can not seem to solve this issue.
When I run the evaluate.py script I get the following error:

Traceback (most recent call last):
  File "evaluate.py", line 234, in <module>
    main()
  File "evaluate.py", line 37, in main
    model = get_model(num_classes=args.num_classes)
AttributeError: 'Namespace' object has no attribute 'num_classes'

If I change the num_classes to anything but 7 I get the following err (this example is without putting in a parameter):

Traceback (most recent call last):
  File "evaluate.py", line 234, in <module>
    main()
  File "evaluate.py", line 41, in main
    model.load_state_dict(saved_state_dict, strict=False)
  File "/home/lukak/anaconda3/envs/CompositionalHumanParsing/lib/python3.6/site-packages/torch/nn/modules/module.py", line 719, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Stream:
	size mismatch for decoder.layer_dsn.3.weight: copying a param of torch.Size([20, 512, 1, 1]) from checkpoint, where the shape is torch.Size([7, 512, 1, 1]) in current model.
	size mismatch for decoder.layer_dsn.3.bias: copying a param of torch.Size([20]) from checkpoint, where the shape is torch.Size([7]) in current model.

When I change the num_classes to 7 I get the following err with long list of missing keys and unexpected keys:

Traceback (most recent call last):
  File "evaluate.py", line 234, in <module>
    main()
  File "evaluate.py", line 41, in main
    model.load_state_dict(saved_state_dict)
  File "/home/lukak/anaconda3/envs/CompositionalHumanParsing/lib/python3.6/site-packages/torch/nn/modules/module.py", line 719, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Stream:
	Missing key(s) in state_dict:  "decoder.layer5.b0.0.weight", "decoder.layer5.b0.1.weight", "decoder.layer5.b0.1.bias", ...
        .
        .
        .
        Unexpected key(s) in state_dict: "decoder.layer6.alpha", "decoder.layer6.conv0.0.weight", "decoder.layer6.conv0.1.weight", ...
        .
        .
        .

I have searched the internet for answers but found nothing that helped and as I am not an experienced software engineer any help would be appreciated.

@ge97qir ge97qir changed the title AttributeError: 'Namespace' object has no attribute 'num_classes' / Missing and Unexpected keys AttributeError: 'Namespace' object has no attribute 'num_classes' / Missing and Unexpected keys in state_dict Jan 14, 2021
@ge97qir
Copy link
Author

ge97qir commented Jan 14, 2021

I also don't understand why there are 7 nodes in the final layer of the model, since there are 20 classes to identify.
Is the model for download correct?

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

1 participant