Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when load state_dict to finetune on ucf101 from pretrained model r2p1d34_K_200ep.pth : Missing key(s) in state_dict #256

Open
nl8590687 opened this issue Jun 3, 2021 · 2 comments

Comments

@nl8590687
Copy link

I am grateful for your works first. I get some problems when I load pretrained model file to R(2+1)D model. I used this command:

python main.py --root_path ../ --video_path ucf101_videos/jpg --annotation_path ucf101_01.json --result_path results --dataset ucf101 --n_classes 101 --n_pretrain_classes 700 --pretrain_path r2p1d34_K_200ep.pth --ft_begin_module fc --model resnet --model_depth 34 --batch_size 128 --n_threads 4 --checkpoint 5

You mentioned the same problem before in issue #15 and #32
But I have installed pytorch 1.8.1+cu102 and run it by GPU. I had downloaded pretrained model r2p1d34_K_200ep.pth
When I run it, I got:

Namespace(accimage=False, annotation_path=WindowsPath('../ucf101_01.json'), arch='resnet-34', batch_size=128, batchnorm_sync=False, begin_epoch=1, checkpoint=5, colorjitter=False, conv1_t_size=7, conv1_t_stride=1, dampening=0.0, dataset='ucf101', dist_url='tcp://127.0.0.1:23456', distributed=False, file_type='jpg', ft_begin_module='fc', inference=False, inference_batch_size=128, inference_crop='center', inference_no_average=False, inference_stride=16, inference_subset='val', input_type='rgb', learning_rate=0.1, lr_scheduler='multistep', manual_seed=1, mean=[0.4345, 0.4051, 0.3775], mean_dataset='kinetics', model='resnet', model_depth=34, momentum=0.9, multistep_milestones=[50, 100, 150], n_classes=700, n_epochs=200, n_finetune_classes=101, n_input_channels=3, n_pretrain_classes=700, n_threads=4, n_val_samples=3, nesterov=False, no_cuda=False, no_hflip=False, no_max_pool=False, no_mean_norm=False, no_std_norm=False, no_train=False, no_val=False, optimizer='sgd', output_topk=5, overwrite_milestones=False, plateau_patience=10, pretrain_path=WindowsPath('../r2p1d34_K_200ep.pth'), resnet_shortcut='B', resnet_widen_factor=1.0, resnext_cardinality=32, result_path=WindowsPath('../results'), resume_path=None, root_path=WindowsPath('..'), sample_duration=16, sample_size=112, sample_t_stride=1, std=[0.2768, 0.2713, 0.2737], tensorboard=False, train_crop='random', train_crop_min_ratio=0.75, train_crop_min_scale=0.25, train_t_crop='random', value_scale=1, video_path=WindowsPath('../ucf101_videos/jpg'), weight_decay=0.001, wide_resnet_k=2, world_size=-1)
loading pretrained model ..\r2p1d34_K_200ep.pth
Traceback (most recent call last):
  File "main.py", line 428, in <module>
    main_worker(-1, opt)
  File "main.py", line 343, in main_worker
    opt.n_finetune_classes)
  File "C:\Users\<username>\Desktop\3D-ResNets-PyTorch\model.py", line 102, in load_pretrained_model
    model.load_state_dict(pretrain['state_dict'])
  File "C:\Users\<username>\anaconda3\envs\py37_pytorch\lib\site-packages\torch\nn\modules\module.py", line 1224, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for ResNet:
        Missing key(s) in state_dict: "conv1.weight", "bn1.weight", "bn1.bias", "bn1.running_mean", "bn1.running_var", "layer1.0.conv1.weight", "layer1.0.bn1.weight", "layer1.0.bn1.bias", "layer1.0.bn1.running_mean", "layer1.0.bn1.running_var", "layer1.0.conv2.weight", "layer1.0.bn2.weight", "layer1.0.bn2.bias", "layer1.0.bn2.running_mean", "layer1.0.bn2.running_var", "layer1.1.conv1.weight", "layer1.1.bn1.weight", "layer1.1.bn1.bias", "layer1.1.bn1.running_mean", "layer1.1.bn1.running_var", "layer1.1.conv2.weight", "layer1.1.bn2.weight", "layer1.1.bn2.bias", "layer1.1.bn2.running_mean", "layer1.1.bn2.running_var", "layer1.2.conv1.weight", "layer1.2.bn1.weight", "layer1.2.bn1.bias", "layer1.2.bn1.running_mean", "layer1.2.bn1.running_var", "layer1.2.conv2.weight", "layer1.2.bn2.weight", "layer1.2.bn2.bias", "layer1.2.bn2.running_mean", "layer1.2.bn2.running_var", "layer2.0.conv1.weight" 
...

Can you tell me what should I do? Thanks!

@NeighborhoodCoding
Copy link

How can I load_state_dict?

@XiangL-Xr
Copy link

model.load_state_dict(pretrain['state_dict'], strict=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants