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

Load pretrained moel failed in Detection #25

Open
zhongtao93 opened this issue Nov 14, 2019 · 5 comments
Open

Load pretrained moel failed in Detection #25

zhongtao93 opened this issue Nov 14, 2019 · 5 comments

Comments

@zhongtao93
Copy link

Hi,

Thank you for sharing code!

I write a simple code for testing an image:

import mmcv
from mmcv.parallel import MMDataParallel, collate, scatter
from mmcv.runner import load_checkpoint
from mmdet.apis import inference_detector, show_result
from mmdet.models import build_backbone, build_detector
cfg = mmcv.Config.fromfile('local_configs/cascade_rcnn_r101_fpn_20e_pretrain_sge_resnet101.py')
cfg.model.pretrained =  'pretrained_model/cascade_rcnn_fpn_20e_sge_resnet101.pth'
model = build_detector(cfg.model, test_cfg=cfg.test_cfg)
_ = load_checkpoint(model, cfg.model.pretrained)
model = MMDataParallel(model, device_ids=[0])
model.eval()
img = mmcv.imread('cat.jpg')
result = inference_detector(model, img, cfg)
show_result(img, result)

while the checkpoint was downloaded from README.MD. I get the error below:

unexpected key in source state_dict: backbone.conv1.weight, backbone.bn1.weight, backbone.bn1.bias, backbone.bn1.running_mean, backbone.bn1.running_var, backbone.bn1.num_batches_tracked, backbone.layer1.0.conv1.weight, backbone.layer1.0.bn1.weight, backbone.layer1.0.bn1.bias, backbone.layer1.0.bn1.running_mean, backbone.layer1.0.bn1.running_var, backbone.layer1.0.bn1.num_batches_tracked, backbone.layer1.0.conv2.weight, backbone.layer1.0.bn2.weight, backbone.layer1.0.bn2.bias, backbone.layer1.0.bn2.running_mean, backbone.layer1.0.bn2.running_var, backbone.layer1.0.bn2.num_batches_tracked, backbone.layer1.0.conv3.weight, back...
missing keys in source state_dict: layer3.1.bn3.running_mean, layer3.5.bn3.running_mean, layer2.1.conv2.weight, layer3.0.downsample.1.bias, layer2.0.downsample.1.running_mean, layer3.3.bn2.running_var, layer3.12.bn1.running_mean, layer2.0.bn1.weight, layer3.4.bn2.running_mean, layer2.1.conv1.weight, layer3.1.bn2.bias, layer3.18.bn1.weight, layer1.2.bn2.weight, layer4.0.bn2.bias, layer3.12.bn2.weight, layer2.0.bn2.running_mean, layer3.11.bn3.weight, layer3.20.bn3.weight, layer1.0.bn2.weight, layer4.2.conv3.weight, layer3.0.downsample.0.weight, layer3.5.bn1.running_mean, layer4.2.conv2.weight, layer3.2.conv3.weight, ...

It seems that the checkpoint file has a prefix 'backbore', but I don't know how to solve it.

Hoping for your reply!

Thank you!

@implus
Copy link
Owner

implus commented Nov 14, 2019

Did you use the version of this repo's detection or the latest mmdetection? This repo's detection code is a little bit out of date, yet the pretrained model is based on it.

@zhongtao93
Copy link
Author

I used the version of this repo's detection, all resource were depended on this repo.

@zhongtao93
Copy link
Author

And it seems that the latest mmdetection doesn't include the config file of cascade_rcnn_fpn_20e_sge_resnet101.py

@implus
Copy link
Owner

implus commented Nov 15, 2019 via email

@implus
Copy link
Owner

implus commented Nov 21, 2019

Hi, I've test the repo again in a new environment with python 3.6 and pytorch 1.1.0, and do not get the loading problem as you describe, e.g., using the pretrained model SGE-ResNet101, to run the test code like:

python tools/test.py local_configs/cascade_rcnn_r101_fpn_20e_pretrain_sge_resnet101.py ../pretrain/cascade_rcnn_fpn_20e_sge_resnet101.pth --gpus 4 --eval bbox

It seems good and get a result of mAP 44.4 . If it works, the code for testing an image can also work well. Could you check it again by renewing your environment and setup the configures in this repo only?

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

2 participants