If you have saved with the pretrained model that is wrapped with nn.DataParallel(), it will have all the state_dict() keys prepended with module.. In this case, while loading the saved state_dict() to a new model, you have to make sure that the new model is wrapped with nn.DataParallel() before calling model.load_state_dict().
I assume, your pretrained model was wrapped using nn.DataParallel(). You have to know how your pretrained model was saved and load it accordingly.



 Mona_Jalal:

new_state_dict = collections.OrderedDict() 
for k, v in model_dic.items(): 
   name = k.replace('module.', '') # remove `module.`
   new_state_dict[name] = v



With the above code, you are already deleting module.. Check if it has really replaced the keys and whether new_state_dict and  model_ft.state_dict() have same keys.