Shakerato

pytorch load pre-trained model, Missing key(s) in state_dict 본문

Research

pytorch load pre-trained model, Missing key(s) in state_dict

Shakeratto 2019. 10. 9. 19:25

In Pytorch

 

Error

'Missing key(s) in state_dict' when loading pre-trained model (state_dict())

 

Reason

In training stage, Use DataParallel for multi gpu usage

In testing stage, Don't use DataParallel

 

Solution

1. In testing stage, Use DataParallel

2. In testing stage, model.load_state_dict(torch.load(path), strict=False)

 

 

 

 

Comments