Pytorch加载模型报错:Missing key(s) in state_dict:

RuntimeError: Error(s) in loading state_dict for attention_net:
	Missing key(s) in state_dict: "pretrained_model.ca.fc1.weight", "pretrained_model.ca.fc2.weight", "pretrained_model.sa.conv1.weight", "pretrained_model.ca1.fc1.weight", "pretrained_model.ca1.fc2.weight", "pretrained_model.sa1.conv1.weight". 

报错原因:可能是网络结构不对。比如你修改了原来的网络结构,加入了一些fc层。但是你加载的参数还是与原来没有fc的网络结构对应的。这时候就会出错。
解决:

model.load_state_dict(state_dict, strict=False)

你可能感兴趣的:(pytorch,深度学习)