implus / PytorchInsight

a pytorch lib with state-of-the-art architectures, pretrained models and real-time updated results
860 stars 123 forks source link

Load pretrained moel failed in Detection #25

Open zhongtao93 opened 5 years ago

zhongtao93 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

zhongtao93 commented 5 years ago

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

implus commented 5 years ago

ok, I'll check it soon.

------------------ 原始邮件 ------------------ 发件人: "Tao Zhong"<notifications@github.com>; 发送时间: 2019年11月15日(星期五) 下午3:19 收件人: "implus/PytorchInsight"<PytorchInsight@noreply.github.com>; 抄送: "子羽牧羊"<674592809@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [implus/PytorchInsight] Load pretrained moel failed in Detection (#25)

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

implus commented 5 years ago

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?