Error when loading pre-trained model

HI, all, A strange error occurred when loading the pre-trained model.
The pre-trained model was trained in Pytorch DataParallel mode. And I try to load the model to test new data.

model = torch.nn.DataParallel(model).cuda()

The pre-trained model is loaded correctly. However if code is modified as

model = model.cuda()

Error occurs as following

  File "/mnt/lustre/zhangyi/pytorch-laneseg/", line 47, in main
  File "/usr/lib64/python2.7/site-packages/torch/nn/modules/", line 331, in load_state_dict
KeyError: 'unexpected key "module.backbone.conv1.weight" in state_dict'

Does DataParallel make difference when loading pre-trained model?

1 Like
1 Like