AttributeError: 'collections.OrderedDict' object has no attribute 'eval'
Simply use:
torch.save(model_conv,'cnn.pt')
the_model = torch.load('cnn.pt')
It is not a model file, instead, this is a state file. In a model file, the complete model is stored, whereas in a state file only the parameters are stored.
So, your OrderedDict
are just values for your model. You will need to create the model and then need to load these values into your model. So, the process will be something in form of
import torch
import torch.nn as nn
class TempModel(nn.Module):
def __init__(self):
self.conv1 = nn.Conv2d(3, 5, (3, 3))
def forward(self, inp):
return self.conv1(inp)
model = TempModel()
model.load_state_dict(torch.load(file_path))
model.eval()
You'll need to define your model properly. The one given in the example above is just a dummy. If you construct your model yourself, you might need to update the keys of the saved dict file as mentioned here. The best course of action is to define your model in exactly the same way from when the state_dict
was saved and then directly executing model.load_state_dict
will work.