问题描述:
The model and loaded state dict do not match exactly.
RuntimeError: Error(s) in loading state_dict for MLMemAESC:Missing key(s) in state_dict.
解决方案:
checkpoint=checkpoint['state_dict']
keys = []
#remove extra module
for k, v in checkpoint.items():
if k.startswith('back'):
continue
keys.append(k)
new_dict = {k: checkpoint[k] for k in keys}
#remove extra key
from collections import OrderedDict
new_dict1 = OrderedDict()
for i, j in new_dict.items():
name = i[5:]
new_dict1[name] = j
head_model.load_state_dict(new_dict1)