Is my model loaded correctly? unexpected_keys

_IncompatibleKeys(missing_keys=['features.0.weight', 'features.0.bias', 'features.2.weight', 'features.2.bias', 'features.5.weight', 'features.5.bias', 'features.7.weight', 'features.7.bias', 'features.10.weight', 'features.10.bias', 'features.12.weight', 'features.12.bias', 'features.14.weight', 'features.14.bias', 'features.18.weight', 'features.18.bias', 'features.20.weight', 'features.20.bias', 'features.22.weight', 'features.22.bias', 'features.26.weight', 'features.26.bias', 'features.28.weight', 'features.28.bias', 'features.30.weight', 'features.30.bias', 'conv6.weight', 'conv6.bias', 'conv7.weight', 'conv7.bias', 'conv8.weight', 'conv8.bias', 'conv9.weight', 'conv9.bias'], unexpected_keys=['architecture', 'epoch', 'state_dict', 'optimizer'])

Getting the above output on model5.load_state_dict(torch.load(path), strict=False). I want to know is my model loaded correctly? I want to use the loaded model to predict some images. I don’t have the [‘architecture’, ‘epoch’, ‘state_dict’, ‘optimizer’] on which the model was trained. Is it possible to load the model without these unexpected_keys=[‘architecture’, ‘epoch’, ‘state_dict’, ‘optimizer’])? If not, how do I pass these values to model5.load_state_dict(torch.load(path), strict=False)

And also is there a way to compare the model before and after doing .load_state_dict

@albanD any suggestions?

The reason is your used nn.Dataparallel. Can u transfer the model to cpu then save it then load it back?.

you can compare the model before and after by looking at any layer weights model.fc1.weight

I actually transfer the model to gpu before loading, could that be the problem? I can not save the model, I have an already trained model.

Usually not.
1.But sometimes when we save the model after transferring it to cpu
2.then if u want to load that saved model again it’s better to load before moving into GPU

Please refer to these below links which are similar

The unexpected keys are actually the keys that the loaded dictionary has. As it is right now, your model is not loaded correctly. Try model5.load_state_dict(torch.load(path)['state_dict'], strict=True).