我培训了一个Efficent-b6模型(架构如下所示):
https://github.com/lukemelas/EfficientNet-PyTorch
现在,我尝试加载一个我用它训练的模型:
checkpoint = torch.load('model.pth', map_location=torch.device('cpu'))
model.load_state_dict(checkpoint, strict=False)
但是我得到了以下错误:
_IncompatibleKeys
missing_keys=['_conv_stem.weight', '_bn0.weight', '_bn0.bias', ...]
unexpected_keys=['module._conv_stem.weight', 'module._bn0.weight', 'module._bn0.bias', ...]
请让我知道如何修复,我遗漏了什么? 谢谢大家!
如果比较
missing_keys
和unexpected_keys
,您可能会意识到发生了什么如您所见,模型权重以
module.
前缀保存。 这是因为你已经用DataParallel
训练了模型现在,要在不使用
DataParallel
的情况下加载模型权重,可以执行以下操作或者,如果使用
DataParallel
包装模型,则不需要上述方法尽管不鼓励第二种方法(因为在许多情况下,您可能不需要
DataParallel
)相关问题 更多 >
编程相关推荐