Attribute Error: collections.OrderedDict' object has no attribute 'eval'

I save my model using the following code.

Path = “Model/model.pth”
torch.save(Network.state_dict(), Path)

Now, i am trying to load the trained model using following code,

model = torch.load(“Model/model.pth”)
model.eval()

But the following error occurred.
AttributeError: ‘collections.OrderedDict’ object has no attribute ‘eval’

You have to do something like this:
Save:

torch.save(model.state_dict(), PATH)

Load:

model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH))
model.eval()

For more information: https://pytorch.org/tutorials/beginner/saving_loading_models.html

1 Like

It worked.
Thank you so much :slight_smile: