video-classification-3d-cnn-pytorch
video-classification-3d-cnn-pytorch copied to clipboard
KeyError: 'unexpected key "module.layer1.0.downsample.0.weight" in state_dict'
when I use resnext-101 model and resnet-152 model, it throws this error. I can seccessfully use resnet-18 model. How to solve this problem?
Could you tell me your settings of options in the execution?
@kenshohara I also meet same problem when i use resnext-101 model The options in my execution is same as default, and i only change the input and output dir
@kenshohara I only change the "model_name", "model_depth" and "model" options
I could run the code by changing the 'shortcut' to 'B' in resnext-101 @xiadingZ sorry to bother u @kenshohara
@CCV-Edward I'm glad the problem solved!
@xiadingZ As mentioned by @CCV-Edward , you should set --resnet_shortcut B to use the models except for resnet-18 and -34.
@kenshohara
I am getting similar error for resnet-34 cpu model. Please let me know needs to be done to rectify this.
python3 main.py --input ./input --video_root ./videos --output ./output.json --model ./resnet-34-kinetics-cpu.pth --mode feature --no_cuda
KeyError: 'unexpected key "module.conv1.weight" in state_dict'
Related to this issue,
resnet-34-kinetics-cpu.pth
includes some problems.
Please download the latest file and try it again.
@kenshohara
well i tried with the latest resnet-34-kinetics-cpu.pth! Can you please provide me the latest cpu model file? Currenty i do not have gpu support.
When did you download the file? I update it 7 days ago. If you tried the latest file, my code or model still include some bugs.
@kenshohara Yes. I used the same(updated on Feb23)!
Do you think solution in below helps. https://discuss.pytorch.org/t/solved-keyerror-unexpected-key-module-encoder-embedding-weight-in-state-dict/1686
Suggestion in the above link is like this, if you saved the model using nn.DataParallel, which stores the model in module, and now trying to load it without DataParallel:
original saved file with DataParallel
state_dict = torch.load('myfile.pth.tar')
create new OrderedDict that does not contain module.
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = k[7:] # remove module.
new_state_dict[name] = v
load params
model.load_state_dict(new_state_dict)
I removed nn.DataParallel from the latest file, and if no_cuda == True, nn.DataParallel does not be used. So I think there are other problems. But I currently confirmed the problem in my environment. Please wait a more few days.
I'm sorry for the long delay. I executed the code using the same options as yours. But I can execute correctly in my environment. I'm not sure what is the problem...
@yash-bhat Did you solve the problem? I encountered the exact same issue as you, and I solved it with the help of this thread, by adding the argument strict=False
to model.load_state_dict
in line 28, main.py.
Hope this helps.
I can declare that you didn't search and examine the code carefully. Actually I used resnet101 these days, and the same problems still exist: