Missing key(s) in state_dict: “features.conv1.weight“
试了网上很多解决方法,最终试出了可行的方法:
把原来的代码:
model.load_state_dict(checkpoint['state_dict'])
替换成:
new_state_dict = OrderedDict()
for k, v in checkpoint.items():
if 'denseblock' in k:
param = k.split(".")
k = ".".join(param[:-3] + [param[-3] + param[-2]] + [param[-1]])
new_state_dict[k] = v
model.load_state_dict(new_state_dict)
可能是版本问题导致的不兼容,需要将键名替换成模型加载权重时所需要的键名
当我以为结束了的时候。。。
错误变成了:Missing key(s) in state_dict: "features.conv0.weight"
又是一番折腾,最终在代码:
model.load_state_dict(new_state_dict,False)
加了一个False,解决了
其实还没结束:)
EOFError: Ran out of input
又出现了新的错误
很迷惑的一个错误,直到我找到了这篇博客:(4条消息) AttributeError: Can't pickle local object 'BaseDataset.img_transformer.<locals>.<lambda>'_weixin_39450145的博客-CSDN博客
将num_workers的值改成了0
test_loader = DataLoader(dataset=test_dataset, batch_size=BATCH_SIZE,
shuffle=False, num_workers=0, pin_memory=True)
解决以上3个问题用了大半天时间,好在CheXNet-master终于可以跑了[撒花]由于显存不够,我只能把BATCH_SIZE直接改成了2(BATCH_SIZE=8的时候显存还是不够),之后打算把代码放到乌邦图上运行,windows太占现存了。
上一篇: theano ValueError: ('setting an array element with a sequence.', 'Container name "None"')
下一篇: pycharm mxnet src/base.cc:49: GPU context requested, but no GPUs found.
推荐阅读
-
pytorch加载模型报错Missing key(s) in state_dict: “classifier00.0.fc.weight“, “classifier00.0.fc.bias“
-
Missing key(s) in state_dict: “module.resnet50.conv1.weight“
-
Missing key(s) in state_dict: “features.conv1.weight“
-
解决Pytorch下报错Missing key(s) in state_dict: "resnet.conv1.0.weight",和 Unexpected key(s) in state_dict
-
Unexpected key(s) in state_dict: “dense_block1.denselayer1.norm.1
-
Error(s) in loading state_dict for DataParallel: Missing key(s) in state_dict: “module.conv0.weight
-
PyTorch 错误 导出onnx提示 Unexpected key(s) in state_dict: “module.classifier.0.weight
-
pytorch加载模型报错Unexpected key(s) in state_dict: module.conv1.weight, module.bn1