Can't Load Trained Classifier Model

Hello I’ve trained ResNet18 model yesterday but can’t load it for inference today. What am I missing?

And when I change the last cell to: model.load_state_dict(checkpoint['state_dict']) it gives me this error:

did you trained it on gpu and now performing the inference on cpu?

You probably saved a dict {"model": models_sd, ...} as checkpoint, so load checkpoint["model"]. (The key information here is not the keys it is missing but the ones that are unexpected.)

Best regards

Thomas

Yes indeed, is it a problem?

I trained it using this tutorial. It uses fast.ai library. Should I use fast.ai library again to infer?

I was using multiple gpu’s and was using nn.DataParallel at the wrong place. So my checkpoint saved the module with the key values, I solved it using the below way-
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = k[7:] # removemodule.``
new_state_dict[name] = v

Now, you are using resnet, so I don’t know exactly how resnet behaves in mutli gpu settings.

try to load in this way
torch.load('my_file.pt', map_location=lambda storage, loc: storage)

Okay solution was using Fast.Ai’s library since I trained using that. Thanks everyone who helped me.