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

Cannot find key 'n_models' #18

Open
LukasMosser opened this issue Oct 16, 2020 · 1 comment
Open

Cannot find key 'n_models' #18

LukasMosser opened this issue Oct 16, 2020 · 1 comment

Comments

@LukasMosser
Copy link

Hi @wjmaddox!

I've been trying to reproduce the results for the segmentation experiment and have hit an error I cannot seem to fix.
I'm using the commands in the readme to train a SWAG model and then to evaluate but I end up with the following error.
Any idea what the reason could be?

python eval_ensemble.py --data_path /home/ec2-user/CamVid/ --batch_size 4 --method SWAG --scale=0.5 --loss cross_entropy --N 50 --file ./experiment_swag/checkpoint-1000.pt --save_path ./experiment_swag/output.npz

/home/ec2-user/CamVid/
Preparing model
Loading model ./experiment_swag/checkpoint-1000.pt

Traceback (most recent call last):
  File "eval_ensemble.py", line 146, in <module>
    model.load_state_dict(checkpoint["state_dict"])
  File "/home/ec2-user/swa_gaussian/swag/posteriors/swag.py", line 182, in load_state_dict
    n_models = state_dict["n_models"].item()

KeyError: 'n_models'
@wjmaddox
Copy link
Owner

Hi,

Just a word of caution here -- we never could really get the segmentation code to reproduce the results in the original Tiramisu paper so I don't know what you'll find there :(...

That being said, it looks like the issue is that you're trying to load a model that does not have a "n_models" buffer in the state dict, so how did you train it?

If you're confident that you indeed trained and are attempting to reload a SWAG model, make sure that the n_models buffer in the script is set to what you trained the model with, and add the strict=False flag as in: model.load_state_dict(checkpoint["state_dict"], strict=False)

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