Loading model appears in load_state_dict raise RuntimeError('Error(s) in loading state_dict

The details of the error (RuntimeError: Error(s) in loading state_dict for Model) are as follows:
Insert image description here

Reason: When training my own model, I used torch.nn.DataParallel to achieve simultaneous training of multiple cards. When loading the trained model for testing without using torch.nn.DataParallel, such an error will be reported.

Solution:
Use descendant code for the model in the code under test

model = torch.nn.DataParallel(model)

Guess you like

Origin blog.csdn.net/m0_50364811/article/details/128224765