ssd.pytorch icon indicating copy to clipboard operation
ssd.pytorch copied to clipboard

Error when reload weights

Open herrickli opened this issue 6 years ago • 5 comments

If I interrupt the process of training, I can not reload the weight ssd300_voc_10000.pth which is the weight trained and saved in weights/, the error information is as follows.

RuntimeError: Error(s) in loading state_dict for ModuleList:
	Missing key(s) in state_dict: "0.bias", "0.weight", "2.bias", "2.weight", "5.bias", "5.weight", "7.bias", "7.weight", "10.bias", "10.weight", "12.bias", "12.weight", "14.bias", "14.weight", "17.bias", "17.weight", "19.bias", "19.weight", "21.bias", "21.weight", "24.bias", "24.weight", "26.bias", "26.weight", "28.bias", "28.weight", "31.bias", "31.weight", "33.bias", "33.weight". 
	Unexpected key(s) in state_dict: "vgg.0.weight", "vgg.0.bias", "vgg.2.weight", "vgg.2.bias", "vgg.5.weight", "vgg.5.bias", "vgg.7.weight", "vgg.7.bias", "vgg.10.weight", "vgg.10.bias", "vgg.12.weight", "vgg.12.bias", "vgg.14.weight", "vgg.14.bias", "vgg.17.weight", "vgg.17.bias", "vgg.19.weight", "vgg.19.bias", "vgg.21.weight", "vgg.21.bias", "vgg.24.weight", "vgg.24.bias", "vgg.26.weight", "vgg.26.bias", "vgg.28.weight", "vgg.28.bias", "vgg.31.weight", "vgg.31.bias", "vgg.33.weight", "vgg.33.bias", "L2Norm.weight", "extras.0.weight", "extras.0.bias", "extras.1.weight", "extras.1.bias", "extras.2.weight", "extras.2.bias", "extras.3.weight", "extras.3.bias", "extras.4.weight", "extras.4.bias", "extras.5.weight", "extras.5.bias", "extras.6.weight", "extras.6.bias", "extras.7.weight", "extras.7.bias", "loc.0.weight", "loc.0.bias", "loc.1.weight", "loc.1.bias", "loc.2.weight", "loc.2.bias", "loc.3.weight", "loc.3.bias", "loc.4.weight", "loc.4.bias", "loc.5.weight", "loc.5.bias", "conf.0.weight", "conf.0.bias", "conf.1.weight", "conf.1.bias", "conf.2.weight", "conf.2.bias", "conf.3.weight", "conf.3.bias", "conf.4.weight", "conf.4.bias", "conf.5.weight", "conf.5.bias". 

Can anyone help me how to solve it ? Thanks!

herrickli avatar Jun 08 '19 04:06 herrickli

To reload the weights, you have to pass it as the --resume parameter to train.py

If you, for example, pass the .pth File to the --basenet parameter, you get this kind of error message, as with "basenet" only the FeatureExtractor -Basenet is initialized, not the Bounding Box regressor

pinkerltm avatar Jun 16 '19 13:06 pinkerltm

set --resume as the path of the pth file

yyx1107 avatar Jul 10 '19 15:07 yyx1107

hi, I have the same problem, did you find a solution? Error(s) in loading state_dict for SSD: Missing key(s) in state_dict: "vgg.0.weight", "vgg.0.bias", "vgg.2.weight", ... Unexpected key(s) in state_dict: "module.vgg.0.weight", "module.vgg.0.bias",...

fatemeakbari avatar Jan 01 '20 07:01 fatemeakbari

hello i met same question. could you help me

bellzhong677 avatar Jul 08 '21 12:07 bellzhong677

If you still have this problem, or anybody finds it later, this would probably fix it (although I haven't tested it): Change:

self.load_state_dict(torch.load(base_file,
map_location=lambda storage, loc: storage))

to

state_dict = torch.load(model, map_location=lambda storage, loc: storage)
state_dict = {k: v for k, v in state_dict["module"].items()}
self.load_state_dict(state_dict)

maarten0912 avatar Dec 22 '21 13:12 maarten0912