[ pytorch ] ——— 报错error解决汇总

 

1、参数没法load进去,多出个module.,原因是:之前训练的时候使用了‘ nn.DataParallel(model_structure,device_ids=gpu_ids) ’

RuntimeError: Error(s) in loading state_dict for ftnet_EncoderDecoder:
	
Missing key(s) in state_dict: 
"BackBone.model.conv1.weight", "BackBone.model.bn1.weight", "BackBone.model.bn1.bias", "BackBone.model.bn1.running_mean", "BackBone.model.bn1.running_var", .....

Unexpected key(s) in state_dict: 
"module.BackBone.model.conv1.weight", "module.BackBone.model.bn1.weight", "module.BackBone.model.bn1.bias", "module.BackBone.model.bn1.running_mean", "module.BackBone.model.bn1.running_var", "module.BackBone.model.l  "  ........

解决:

model_structure = net()
model_structure = nn.DataParallel(model_structure,device_ids=gpu_ids)
model = load_network(model_structure)

 

2、There is an imbalance between your GPUs. You may want to exclude GPU 0 which has less than 75% of the memory or cores of GPU 1. You can do so by setting the device_ids argument to DataParallel, or by setting the CUDA_VISIBLE_DEVICES environment variable.

解决:

As mentioned in this link, you have to do model.cuda() before passing it to nn.DataParallel.

net = nn.DataParallel(model.cuda(), device_ids=[0,1])

URL that solved this problem:https://stackoverflow.com/questions/55343893/how-to-do-parallel-processing-in-pytorch
 

你可能感兴趣的:(Pytorch)