if args.loadmodel is not None:
state_dict = torch.load(args.loadmodel)
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = k[0:9] + k[16:] # remove `module.`
if k[0] == 'f':
new_state_dict[name] = v
else:
new_state_dict[k] = v
model.load_state_dict(new_state_dict['state_dict'])
model.cpu()
the error is:
KeyError: ‘unexpected key “module.feature_extraction.firstconv.0.0.weight” in state_dict’