PytorchInsight icon indicating copy to clipboard operation
PytorchInsight copied to clipboard

Load pretrained moel failed in Detection

Open zhongtao93 opened this issue 5 years ago • 5 comments

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!

zhongtao93 avatar Nov 14 '19 07:11 zhongtao93

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.

implus avatar Nov 14 '19 13:11 implus

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

zhongtao93 avatar Nov 15 '19 07:11 zhongtao93

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

zhongtao93 avatar Nov 15 '19 07:11 zhongtao93

ok, I'll check it soon.

------------------ 原始邮件 ------------------ 发件人: "Tao Zhong"<[email protected]>; 发送时间: 2019年11月15日(星期五) 下午3:19 收件人: "implus/PytorchInsight"<[email protected]>; 抄送: "子羽牧羊"<[email protected]>;"Comment"<[email protected]>; 主题: 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 avatar Nov 15 '19 10:11 implus

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?

implus avatar Nov 21 '19 07:11 implus