ahmetgunduz / Real-time-GesRec

Real-time Hand Gesture Recognition with PyTorch on EgoGesture, NvGesture, Jester, Kinetics and UCF101
https://arxiv.org/abs/1901.10323
MIT License
626 stars 166 forks source link

Get stuck at running online_test.py with pretrained model on CPU #40

Open Kyle0936 opened 4 years ago

Kyle0936 commented 4 years ago

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:

  1. added opt.no_cuda = True right after opt = parse_opts_online()
  2. added map_location=torch.device('cpu') to torch.load(opt.pretrain_path)
  3. 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", ...

solved by looking into here

However, now it gives me an error:

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]).

Thanks in advance!!!

ahmetgunduz commented 4 years ago

@KKKKKyle could you please pull the latest version of the codebase and provide pretrain_modality parameter for the model being loaded.