i am trying to load a model in pytorch
but getting following error
import torch
from models import micro_models
model = micro_models.NetworkCIFAR
model.load_state_dict(torch.load("model.pth"))
last line is showing following error
Traceback (most recent call last):
File “”, line 1, in
TypeError: load_state_dict() missing 1 required positional argument: ‘state_dict’
Ok. I tried to provide load_state_dict() with incompatible dict object and I get different error (“Error(s) in loading state_dict”)
It is a snippet:
model = torchvision.models.resnet18()
od = OrderedDict()
torch.save(od, 'tmp.pt')
model.load_state_dict(od)
model.load_state_dict(torch.load('tmp.pt'))
The only way I can reproduce the error “TypeError: load_state_dict() missing 1 required positional argument: ‘state_dict’” is actually to call this function without any arguments like this model.load_state_dict()
Also, I noticed that error came from line 1 of some file “”, complaining no argument is provided to load_state_dict(). While I can’t look into that file it is hard to tell any further