kenshohara / 3D-ResNets-PyTorch

3D ResNets for Action Recognition (CVPR 2018)
MIT License
3.91k stars 933 forks source link

Can I use resnext-101-kinetics-ucf101_split1.pt directly to test? #127

Open xiaoiker opened 5 years ago

xiaoiker commented 5 years ago

Hello, I download your pretrained model resnext-101-kinetics-ucf101_split1.pt and want to test it directly on ucf101, But I get 0 accuracy. What should be the problem? Should I still finetuning it before I test?

zx1009737297 commented 5 years ago

I have the same question.Do you solve the question?

xiaoiker commented 5 years ago

I have the same question.Do you solve the question?

Finally, I found it. The reason is that the generate_model(opt) function, for any model, default to remove the last FC layer, so you can comment these lines in generate_model(opt), then you will get a accuracy around 86%:

` if not opt.no_cuda: model = model.cuda() model = nn.DataParallel(model, device_ids=None)

    if opt.pretrain_path:
        print('loading pretrained model {}'.format(opt.pretrain_path))
        pretrain = torch.load(opt.pretrain_path)
        assert opt.arch == pretrain['arch']

        model.load_state_dict(pretrain['state_dict'])

        if opt.model == 'densenet':
            model.module.classifier = nn.Linear(
                model.module.classifier.in_features, opt.n_finetune_classes)
            model.module.classifier = model.module.classifier.cuda()

#### comment these 3 lines else: model.module.fc = nn.Linear(model.module.fc.in_features, opt.n_finetune_classes) model.module.fc = model.module.fc.cuda()

        parameters = get_fine_tuning_parameters(model, opt.ft_begin_index)
        return model, parameters` 
zx1009737297 commented 5 years ago

I try your solution,but I also get 0 accuracy.And running half of the codes ,it went wrong .Can you tell me your specific steps? Thank you !

xiaoiker commented 5 years ago
  1. Download the pretrain model: resnext-101-kinetics-ucf101_split1.pt
  2. Change the pretrain model path in the in the opts.py( or set from the command line)
  3. Comment the lines I mentioned before
  4. Run main.py without training by add --no_train
zx1009737297 commented 5 years ago

Thank you for your steps! I tried as you said,but it went wrong.Can you help me?

loading checkpoint /home/chen/Desktop/UCF/resnet-18-kinetics-ucf101_split1.pth Traceback (most recent call last): File "main.py", line 131, in model.load_state_dict(state_dict) File "/home/chen/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 769, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for DataParallel: Missing key(s) in state_dict: "module.conv1.weight", "module.bn1.weight", "module.bn1.bias", "module.bn1.running_mean", "module.bn1.running_var", "module.layer1.0.conv1.weight", "module.layer1.0.bn1.weight", "module.layer1.0.bn1.bias", "module.layer1.0.bn1.running_mean", "module.layer1.0.bn1.running_var", "module.layer1.0.conv2.weight", "module.layer1.0.bn2.weight", "module.layer1.0.bn2.bias", "module.layer1.0.bn2.running_mean", "module.layer1.0.bn2.running_var", "module.layer1.1.conv1.weight", "module.layer1.1.bn1.weight", "module.layer1.1.bn1.bias", "module.layer1.1.bn1.running_mean", "module.layer1.1.bn1.running_var", "module.layer1.1.conv2.weight", "module.layer1.1.bn2.weight", "module.layer1.1.bn2.bias", "module.layer1.1.bn2.running_mean", "module.layer1.1.bn2.running_var", "module.layer2.0.conv1.weight", "module.layer2.0.bn1.weight", "module.layer2.0.bn1.bias", "module.layer2.0.bn1.running_mean", "module.layer2.0.bn1.running_var", "module.layer2.0.conv2.weight", "module.layer2.0.bn2.weight", "module.layer2.0.bn2.bias", "module.layer2.0.bn2.running_mean", "module.layer2.0.bn2.running_var", "module.layer2.0.downsample.0.weight", "module.layer2.0.downsample.1.weight", "module.layer2.0.downsample.1.bias", "module.layer2.0.downsample.1.running_mean", "module.layer2.0.downsample.1.running_var", "module.layer2.1.conv1.weight", "module.layer2.1.bn1.weight", "module.layer2.1.bn1.bias", "module.layer2.1.bn1.running_mean", "module.layer2.1.bn1.running_var", "module.layer2.1.conv2.weight", "module.layer2.1.bn2.weight", "module.layer2.1.bn2.bias", "module.layer2.1.bn2.running_mean", "module.layer2.1.bn2.running_var", "module.layer3.0.conv1.weight", "module.layer3.0.bn1.weight", "module.layer3.0.bn1.bias", "module.layer3.0.bn1.running_mean", "module.layer3.0.bn1.running_var", "module.layer3.0.conv2.weight", "module.layer3.0.bn2.weight", "module.layer3.0.bn2.bias", "module.layer3.0.bn2.running_mean", "module.layer3.0.bn2.running_var", "module.layer3.0.downsample.0.weight", "module.layer3.0.downsample.1.weight", "module.layer3.0.downsample.1.bias", "module.layer3.0.downsample.1.running_mean", "module.layer3.0.downsample.1.running_var", "module.layer3.1.conv1.weight", "module.layer3.1.bn1.weight", "module.layer3.1.bn1.bias", "module.layer3.1.bn1.running_mean", "module.layer3.1.bn1.running_var", "module.layer3.1.conv2.weight", "module.layer3.1.bn2.weight", "module.layer3.1.bn2.bias", "module.layer3.1.bn2.running_mean", "module.layer3.1.bn2.running_var", "module.layer4.0.conv1.weight", "module.layer4.0.bn1.weight", "module.layer4.0.bn1.bias", "module.layer4.0.bn1.running_mean", "module.layer4.0.bn1.running_var", "module.layer4.0.conv2.weight", "module.layer4.0.bn2.weight", "module.layer4.0.bn2.bias", "module.layer4.0.bn2.running_mean", "module.layer4.0.bn2.running_var", "module.layer4.0.downsample.0.weight", "module.layer4.0.downsample.1.weight", "module.layer4.0.downsample.1.bias", "module.layer4.0.downsample.1.running_mean", "module.layer4.0.downsample.1.running_var", "module.layer4.1.conv1.weight", "module.layer4.1.bn1.weight", "module.layer4.1.bn1.bias", "module.layer4.1.bn1.running_mean", "module.layer4.1.bn1.running_var", "module.layer4.1.conv2.weight", "module.layer4.1.bn2.weight", "module.layer4.1.bn2.bias", "module.layer4.1.bn2.running_mean", "module.layer4.1.bn2.running_var", "module.fc.weight", "module.fc.bias". Unexpected key(s) in state_dict: "layer1.0.bn1.bias", "layer2.0.bn2.running_var", "layer3.1.bn1.running_mean", "layer2.1.bn1.running_var", "layer1.1.bn1.bias", "layer1.0.bn1.weight", "layer4.1.bn2.weight", "layer2.1.bn1.weight", "layer1.1.conv1.weight", "layer3.1.bn1.weight", "bn1.running_var", "layer4.1.bn2.bias", "layer1.1.bn2.running_var", "layer4.1.conv2.weight", "layer1.0.bn2.bias", "layer4.1.bn1.running_var", "layer3.1.bn2.bias", "layer2.0.bn2.bias", "layer2.0.bn1.bias", "layer4.0.conv2.weight", "layer2.1.conv2.weight", "layer3.0.bn2.bias", "layer4.1.bn2.running_mean", "layer4.1.bn1.running_mean", "layer3.1.bn1.running_var", "layer2.0.conv2.weight", "layer1.1.bn1.running_var", "layer3.1.conv1.weight", "layer2.1.bn2.weight", "layer4.0.bn2.bias", "bn1.running_mean", "bn1.weight", "layer4.0.bn1.bias", "layer1.0.bn1.running_mean", "layer1.1.bn1.running_mean", "layer2.1.bn2.running_mean", "layer1.0.conv2.weight", "layer1.0.bn1.running_var", "layer3.1.bn2.weight", "layer2.1.bn2.running_var", "layer3.0.conv1.weight", "layer4.0.bn2.running_mean", "layer4.0.conv1.weight", "layer3.0.conv2.weight", "layer1.0.bn2.weight", "fc.weight", "layer4.0.bn2.weight", "layer3.0.bn1.running_var", "layer4.1.conv1.weight", "layer2.0.bn2.running_mean", "layer4.1.bn2.running_var", "layer3.0.bn1.weight", "layer3.1.bn2.running_var", "layer3.0.bn2.weight", "layer2.1.bn1.bias", "layer2.0.bn1.running_var", "layer3.0.bn1.bias", "layer1.1.bn2.bias", "layer3.0.bn2.running_var", "layer4.1.bn1.bias", "layer1.1.bn2.weight", "conv1.weight", "layer4.0.bn1.running_mean", "layer4.0.bn2.running_var", "layer2.0.bn2.weight", "layer2.0.conv1.weight", "layer3.1.bn2.running_mean", "layer2.0.bn1.weight", "layer4.0.bn1.weight", "layer3.0.bn1.running_mean", "layer2.1.bn2.bias", "layer1.1.bn1.weight", "layer3.1.bn1.bias", "layer2.1.conv1.weight", "bn1.bias", "layer1.1.bn2.running_mean", "layer4.1.bn1.weight", "layer3.0.bn2.running_mean", "layer2.0.bn1.running_mean", "layer4.0.bn1.running_var", "layer2.1.bn1.running_mean", "layer1.1.conv2.weight", "layer1.0.conv1.weight", "fc.bias", "layer3.1.conv2.weight", "layer1.0.bn2.running_var", "layer1.0.bn2.running_mean".

Esaada commented 5 years ago

youre probably trying to run it on your cpu, and the weights were trained on a GPU with dataparallel. you need to erase the module inside the names of the weights.

slighting666 commented 4 years ago

@xiaoiker @zx1009737297 @cagbal @skamdar Hi, I got the accuracy of val.log, but I want to calculate the accuracy of video level, where can I get the val.json file and how to use eval_ucf101.py?