Hello, everyone,
I trained a resnet34 model using mainModel.py on my image sets. However, when I tried to evalue its acurracy, I met the following problem.
I first create a model
model = models.dict’resnet34’
Then I loaded the model
checkpoint=torch.load(’./model_best10000.pth.tar’)
# create new OrderedDict that does not contain module.
from collections import OrderedDict
new_checkpoint = OrderedDict()
for k, v in checkpoint.items():
name = k[7:] # remove module.
new_checkpoint[name] = v
load params
model.load_state_dict(new_checkpoint[‘state_dict’])
However I got the following error message
Traceback (most recent call last):
File “testAccuracy.py”, line 94, in 
model.load_state_dict(new_checkpoint[‘state_dict’])
KeyError: ‘state_dict’
Anyone can tell me what is the problem and how to fix it?
Thanks in advance!
Nam