jfzhang95 / pytorch-video-recognition

PyTorch implemented C3D, R3D, R2Plus1D models for video activity recognition.
MIT License
1.16k stars 250 forks source link

KeyError: 'state_dict' when running inference.py file #24

Open abhisingh32 opened 5 years ago

abhisingh32 commented 5 years ago

---> 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'

masju96 commented 5 years ago

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

yizt commented 5 years ago

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)
liuhengyue commented 4 years ago

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?

skyqwe123 commented 3 years ago

---> 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

lackofname commented 1 year ago

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