# Missing keys & unexpected keys in state\_dict when loading self trained model

**URL:** <https://discuss.pytorch.org/t/missing-keys-unexpected-keys-in-state-dict-when-loading-self-trained-model/22379>\
**Category:** vision\
**Created:** [August 3, 2018, 11:43am UTC](https://discuss.pytorch.org/t/missing-keys-unexpected-keys-in-state-dict-when-loading-self-trained-model/22379 "2018-08-03T11:43:15Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![lelegu](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/96bed5/32.png) [@lelegu](https://discuss.pytorch.org/u/lelegu)\
**Post date:** [March 20, 2020, 3:27pm UTC](https://discuss.pytorch.org/t/missing-keys-unexpected-keys-in-state-dict-when-loading-self-trained-model/22379/12 "2020-03-20T15:27:17Z")

</div>

I use `torch.save(model.state_dict(), 'file_name.pt')` to save the model. If I don’t use `nn.DataParallel` to save model, I also don’t need it when I load it, right?  
If so, when I `torch.save(model.state_dict(), 'mymodel.pt')` in one py file during training, I try to load it in a new file with `model.load_state_dict(torch.load('mymodel.pt))` , it gives me the error  
`RuntimeError: Error(s) in loading state_dict for model: Missing key(s) in state_dict: "l1.W", "l1.b", "l2.W", "l2.b".`  
My model is a self-defined model with two self-constructed layers l1 and l2, each has parameter W and b.  
Can you give me any answer to it? Thanks!

---

_[View the full topic](https://discuss.pytorch.org/t/missing-keys-unexpected-keys-in-state-dict-when-loading-self-trained-model/22379)._
