报错信息:
RuntimeError: Error(s) in loading state_dict for ResNet:
Missing key(s) in state_dict: “conv1.weight”, “bn1.running_var”, “bn1.bias”, “bn1.running_mean”, “bn1.weight”, “layer1.0.conv1.weight”, “layer1.0.bn1.running_var”, “layer1.0.bn1.bias”, 后面省略一大堆
原因:加载使用模型时和训练模型时的环境不一致
解决方法:
出错代码
checkpoint = torch.load(model)
net.load_state_dict(checkpoint['net'])
net.cuda()
改为
checkpoint = torch.load(model)
net.load_state_dict(checkpoint['net'], False)
net.cuda()