mmfewshot icon indicating copy to clipboard operation
mmfewshot copied to clipboard

unexpected key in source state_dict

Open wang-kangkang opened this issue 3 years ago • 5 comments

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?

wang-kangkang avatar Apr 19 '22 13:04 wang-kangkang

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

BIGWangYuDong avatar May 04 '22 04:05 BIGWangYuDong

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

wang-kangkang avatar May 04 '22 16:05 wang-kangkang

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

isJunCheng avatar May 11 '22 08:05 isJunCheng

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

BIGWangYuDong avatar May 12 '22 10:05 BIGWangYuDong

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!

isJunCheng avatar May 12 '22 12:05 isJunCheng