Error(s) in loading state_dict for DataParallel
写在前面
前提是一开始模型训练在单卡上,想转到多卡,resume 模型报错没有 module 模块
没有几行的正式开始
参考这个
在加载模型的地方修改一下:
state_dict =checkpoint['state_dict']
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
if 'module' not in k:
k = 'module.'+k
else:
k = k.replace('features.module.', 'module.features.')
new_state_dict[k]=v
model.load_state_dict(new_state_dict)
还没有评论,来说两句吧...