pytorch-video-recognition icon indicating copy to clipboard operation
pytorch-video-recognition copied to clipboard

KeyError: 'state_dict' when running inference.py file

Open abhisingh32 opened this issue 6 years ago • 5 comments
trafficstars

---> 32 model.load_state_dict(checkpoint['state_dict']) 33 # model.load_state_dict(torch.load("C:\Users####\pytorch-video-recognition\c3d-pretrained.pth.tar", map_location=lambda storage, loc: storage)) 34

KeyError: 'state_dict'

abhisingh32 avatar Apr 29 '19 05:04 abhisingh32

Same error here, can't load the pre-trained model. Has someone solved it? Thanks in advance

masju96 avatar Jun 05 '19 09:06 masju96

change model.load_state_dict(checkpoint['state_dict']) to

    state_dict = model.state_dict()
    for k1, k2 in zip(state_dict.keys(), checkpoint.keys()):
        state_dict[k1] = checkpoint[k2]
    model.load_state_dict(state_dict)

yizt avatar Jun 19 '19 01:06 yizt

Hi, thanks for sharing the great codes! When I load the pre-trained model, the number of class for saved weights of classifier.6 is 487. Is there any explanation on that?

liuhengyue avatar Jul 11 '19 21:07 liuhengyue

---> 32 model.load_state_dict(checkpoint['state_dict']) 33 # model.load_state_dict(torch.load("C:\Users####\pytorch-video-recognition\c3d-pretrained.pth.tar", map_location=lambda storage, loc: storage)) 34

KeyError: 'state_dict'

model = C3D.C3D(num_classes=101, pretrained=True)
# checkpoint = torch.load('c3d-pretrained.pth', map_location=lambda storage, loc: storage)
# model.load_state_dict(checkpoint['state_dict'])
model.to(device)
model.eval()

That's OK

skyqwe123 avatar Mar 09 '21 14:03 skyqwe123

thanks for the code! any clue where I can find model.load_state_dict(checkpoint['state_dict'])

lackofname avatar Feb 11 '23 09:02 lackofname