open-mmlab / mmfewshot

OpenMMLab FewShot Learning Toolbox and Benchmark
https://mmfewshot.readthedocs.io/en/latest/
Apache License 2.0
698 stars 117 forks source link

unexpected key in source state_dict #73

Open wang-kangkang opened 2 years ago

wang-kangkang commented 2 years ago

in my log, it will be see: unexpected key in source state_dict if i set pretrained = 'open-mmlab://detectron2/resnet50_caffe' in configs/detection/base/models/faster_rcnn_r50_caffe_c4.py, the log print "unexpected key in source state_dict: conv1.weight, ......" if i set pretrained = 'iter_20000.pth', this is the saved model, the log print "unexpected key in source state_dict: backbone.conv1.weight, ......" does it mean I didn't load any parameters? how to solve this problem?

BIGWangYuDong commented 2 years ago

if i set pretrained = 'open-mmlab://detectron2/resnet50_caffe' in configs/detection/base/models/faster_rcnn_r50_caffe_c4.py, the log print "unexpected key in source state_dict: conv1.weight, ......"

More details are needed, for example your logging file.

if i set pretrained = 'iter_20000.pth', this is the saved model, the log print "unexpected key in source state_dict: backbone.conv1.weight, ......"

This is mainly because your backbone conv layer name does not match the pretrained backbone checkpoint. If you want to use iter_20000.pth as pretrained

model = dict(
    backbone=dict(
        init_cfg=dict(
            type='Pretrained', prefix='backbone.', checkpoint='open-mmlab://detectron2/resnet50_caffe')))

also please note that pretrained is only used in the backbone. if you want to use the whole pretrained ckpt, please use load_from

wang-kangkang commented 2 years ago

if i set pretrained = 'open-mmlab://detectron2/resnet50_caffe' in configs/detection/base/models/faster_rcnn_r50_caffe_c4.py, the log print "unexpected key in source state_dict: conv1.weight, ......"

More details are needed, for example your logging file.

if i set pretrained = 'iter_20000.pth', this is the saved model, the log print "unexpected key in source state_dict: backbone.conv1.weight, ......"

This is mainly because your backbone conv layer name does not match the pretrained backbone checkpoint. If you want to use iter_20000.pth as pretrained

model = dict(
    backbone=dict(
        init_cfg=dict(
            type='Pretrained', prefix='backbone.', checkpoint='open-mmlab://detectron2/resnet50_caffe')))

also please note that pretrained is only used in the backbone. if you want to use the whole pretrained ckpt, please use load_from

i know the load_from, what i mean is the default code has a problem. Did you actually run the code yourself? I clone the code, and I don't change anything, and then report unexpected keys

isJunCheng commented 2 years ago

if i set pretrained = 'open-mmlab://detectron2/resnet50_caffe' in configs/detection/base/models/faster_rcnn_r50_caffe_c4.py, the log print "unexpected key in source state_dict: conv1.weight, ......"

More details are needed, for example your logging file.

if i set pretrained = 'iter_20000.pth', this is the saved model, the log print "unexpected key in source state_dict: backbone.conv1.weight, ......"

This is mainly because your backbone conv layer name does not match the pretrained backbone checkpoint. If you want to use iter_20000.pth as pretrained

model = dict(
    backbone=dict(
        init_cfg=dict(
            type='Pretrained', prefix='backbone.', checkpoint='open-mmlab://detectron2/resnet50_caffe')))

also please note that pretrained is only used in the backbone. if you want to use the whole pretrained ckpt, please use load_from

i know the load_from, what i mean is the default code has a problem. Did you actually run the code yourself? I clone the code, and I don't change anything, and then report unexpected keys

I also encountered the same problem! Have you solved it? My code didn't run successfully. image image

BIGWangYuDong commented 2 years ago

What config did you use? configs/detection/base/models/faster_rcnn_r50_caffe_c4.py is not the whole config file. I haven't met this error in MMDet before

isJunCheng commented 2 years ago

What config did you use? configs/detection/base/models/faster_rcnn_r50_caffe_c4.py is not the whole config file. I haven't met this error in MMDet before

thanks for your reply! after i reinstall the env and code, the problem disappears. but, i don't understand how to divide data sets now..... i looked at the training method of 'attention RPN' on coco(attention-rpn_r50_c4_4xb2_coco_official-base-training.py and attention-rpn_r50_c4_4xb2_coco_official-10shot-fine-tuning.py), and made statistics on the base set and few-shot set used by them. I found that the samples in the few-shot set have used a large number of samples for training in base training. I don't know what this is! in base train image in few-shot train image

can you help me? Hope to get your reply, thanks!