1.由于用DataParallel训练的模型数据并行方式的,key中会包含”module“关键字,故会出现以下错误
解决:去掉DataParallel 预训练model中的module,修改如下:
2.报以下错误时需去掉'running_mean', 'running_var'
结合1中的修改,最终修改结果如下:
3. 当只使用cpu时还可能报以下错误:
此时将 weights = torch.load(opt.pretrained)["model"].state_dict()改为weights = torch.load(opt.pretrained, map_location=torch.device('cpu'))["model"].state_dict()即可