I want to load the model trained on single GPU previously to multi-Gpu now, but got an error:
KeyError: ‘unexpected key “conv1.weight” in state_dict’
what could be the problem?
this is my code:
net = Net()
#using Gpus
if torch.cuda.is_available():
print("cuda is available...")
if torch.cuda.device_count() > 1:
print('using %d Gpus'%torch.cuda.device_count())
net=nn.DataParallel(net)
net.cuda()
else:
print('cuda disabled')
print(net)
save_path='/gdata/0510nnoptim_withTV_0.1.pt'
param_path='/gdata/0507nnoptim_withTV_1.pt'
if param_path is None:
net.apply(weights_init)
print('random initialize parameters')
else:
net.load_state_dict(torch.load(param_path))
print('load parameters from: ', param_path)