Loading saved model

Hi,

I have used an alexnet model that is available in pytorch models and modified the last layer of the alexnet to suit my requirements and have trained this model and saved the trained weights.
Now whenever i try to load the saved weights i keep getting the error given below.

Some help and insight on this would be appreciated.

Thanks.

torch.save(alexNet.state_dict(),'./cifar_net.pth')
new_models=models.alexnet()
new_models.classifier[6]=nn.Sequential(nn.Linear(4096,10))
new_models=torch.load('./cifar_net.pth')
new_models.eval()

and the output i get is-

AttributeError: 'collections.OrderedDict' object has no attribute 'eval'

I also get the same error when i try to load the model using-

new_models.load_state_dict(torch.load('./cifar_net.pth'))

You should’t get that error using new_models.load_state_dict(torch.load('./cifar_net.pth')), because this is the right way to load a model, not new_models=torch.load('./cifar_net.pth'), beacuse this doesn’t load the weights to the model, but only loading the dict on the new_model variable

1 Like