I was trying to run oneline_test.py with pretrained model on CPU (w/o CUDA). I did some modification in model.py and online_test.py, including:
added opt.no_cuda = True right after opt = parse_opts_online()
added map_location=torch.device('cpu') to torch.load(opt.pretrain_path)
modified model.load_state_dict(pretrain['state_dict'])at line 120ish to
state_dict =pretrain['state_dict']
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
if 'module' in k:
name = k[7:] # remove 'module.' of dataparallel
new_state_dict[name]=v
model.load_state_dict(new_state_dict)
Solved the issue of
Missing key(s) in state_dict: "conv1.weight",...
Unexpected key(s) in state_dict: "module.conv1.weight", ...
Traceback (most recent call last):
File "online_test.py", line 138, in <module>
detector,classifier = load_models(opt)
File "online_test.py", line 76, in load_models
detector, parameters = generate_model(opt)
File "...../Real-time-GesRec-master/model.py", line 132, in generate_model
model.load_state_dict(new_state_dict)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/nn/modules/module.py", line 845, in load_state_dict
self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for ResNetL:
size mismatch for conv1.weight: copying a param with shape torch.Size([16, 1, 7, 7, 7]) from checkpoint, the shape in current model is torch.Size([16, 3, 7, 7, 7]).
I was trying to run oneline_test.py with pretrained model on CPU (w/o CUDA). I did some modification in model.py and online_test.py, including:
opt.no_cuda = True
right afteropt = parse_opts_online()
map_location=torch.device('cpu')
totorch.load(opt.pretrain_path)
model.load_state_dict(pretrain['state_dict'])
at line 120ish toSolved the issue of
solved by looking into here
However, now it gives me an error:
Thanks in advance!!!