C-3-Framework icon indicating copy to clipboard operation
C-3-Framework copied to clipboard

Missing key(s) in state_dict: "CCN.frontend.0.weight",Unexpected key(s) in state_dict: "CCN.module.frontend.0.weight"

Open scalaboy opened this issue 5 years ago • 5 comments

python test.py

Traceback (most recent call last): File "test.py", line 153, in main() File "test.py", line 50, in main test(file_list[0], model_path) File "test.py", line 56, in test net.load_state_dict(torch.load(model_path)) File "/home/deeplp/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 839, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for CrowdCounter: Missing key(s) in state_dict: "CCN.frontend.0.weight", "CCN.frontend.0.bias", "CCN.frontend.2.weight", "CCN.frontend.2.bias", "CCN.frontend.5.weight", "CCN.frontend.5.bias", "CCN.frontend.7.weight", "CCN.frontend.7.bias", "CCN.frontend.10.weight", "CCN.frontend.10.bias", "CCN.frontend.12.weight", "CCN.frontend.12.bias", "CCN.frontend.14.weight", "CCN.frontend.14.bias", "CCN.frontend.17.weight", "CCN.frontend.17.bias", "CCN.frontend.19.weight", "CCN.frontend.19.bias", "CCN.frontend.21.weight", "CCN.frontend.21.bias", "CCN.backend.0.weight", "CCN.backend.0.bias", "CCN.backend.2.weight", "CCN.backend.2.bias", "CCN.backend.4.weight", "CCN.backend.4.bias", "CCN.backend.6.weight", "CCN.backend.6.bias", "CCN.backend.8.weight", "CCN.backend.8.bias", "CCN.backend.10.weight", "CCN.backend.10.bias", "CCN.output_layer.weight", "CCN.output_layer.bias". Unexpected key(s) in state_dict: "CCN.module.frontend.0.weight", "CCN.module.frontend.0.bias", "CCN.module.frontend.2.weight", "CCN.module.frontend.2.bias", "CCN.module.frontend.5.weight", "CCN.module.frontend.5.bias", "CCN.module.frontend.7.weight", "CCN.module.frontend.7.bias", "CCN.module.frontend.10.weight", "CCN.module.frontend.10.bias", "CCN.module.frontend.12.weight", "CCN.module.frontend.12.bias", "CCN.module.frontend.14.weight", "CCN.module.frontend.14.bias", "CCN.module.frontend.17.weight", "CCN.module.frontend.17.bias", "CCN.module.frontend.19.weight", "CCN.module.frontend.19.bias", "CCN.module.frontend.21.weight", "CCN.module.frontend.21.bias", "CCN.module.backend.0.weight", "CCN.module.backend.0.bias", "CCN.module.backend.2.weight", "CCN.module.backend.2.bias", "CCN.module.backend.4.weight", "CCN.module.backend.4.bias", "CCN.module.backend.6.weight", "CCN.module.backend.6.bias", "CCN.module.backend.8.weight", "CCN.module.backend.8.bias", "CCN.module.backend.10.weight", "CCN.module.backend.10.bias", "CCN.module.output_layer.weight", "CCN.module.output_layer.bias". deeplp@deeplp:/deeplp/mainspace

scalaboy avatar Jan 08 '20 10:01 scalaboy

remove the "module."

gjy3035 avatar Jan 08 '20 11:01 gjy3035

where to remove,the module is in the model 07-CSRNet_all_ep_39_mae_32.6_mse_74.3.pth?

scalaboy avatar Jan 08 '20 14:01 scalaboy

https://github.com/gjy3035/C-3-Framework/issues/22#issuecomment-494287652

gjy3035 avatar Jan 09 '20 00:01 gjy3035

where to remove,the module is in the model 07-CSRNet_all_ep_39_mae_32.6_mse_74.3.pth? try this:

from collections import OrderedDict 
import torch

model_in = 'model_in.pth'
statedict = torch.load(model_in) 

statedict_new = OrderedDict() 
for statekey in statedict:
    statekey_new = statekey.replace('.module','')
    statedict_new[statekey_new] = statedict[statekey]

torch.save(statedict_new, 'model_out.pth')

larosi avatar Jan 10 '20 14:01 larosi

where to remove,the module is in the model 07-CSRNet_all_ep_39_mae_32.6_mse_74.3.pth? try this:

from collections import OrderedDict 
import torch

model_in = 'model_in.pth'
statedict = torch.load(model_in) 

statedict_new = OrderedDict() 
for statekey in statedict:
    statekey_new = statekey.replace('.module','')
    statedict_new[statekey_new] = statedict[statekey]

torch.save(statedict_new, 'model_out.pth')

thank you!!

MingboHong avatar Jun 05 '20 09:06 MingboHong