open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.31k stars 9.42k forks source link

The model and loaded state dict do not match exactly #10684

Open Twisted-Fates opened 1 year ago

Twisted-Fates commented 1 year ago

image

`The model and loaded state dict do not match exactly

size mismatch for roi_head.bbox_head.fc_cls.weight: copying a param with shape torch.Size([81, 1024]) from checkpoint, the shape in current model is torch.Size([5, 1024]).
size mismatch for roi_head.bbox_head.fc_cls.bias: copying a param with shape torch.Size([81]) from checkpoint, the shape in current model is torch.Size([5]).
size mismatch for roi_head.bbox_head.fc_reg.weight: copying a param with shape torch.Size([320, 1024]) from checkpoint, the shape in current model is torch.Size([16, 1024]).
size mismatch for roi_head.bbox_head.fc_reg.bias: copying a param with shape torch.Size([320]) from checkpoint, the shape in current model is torch.Size([16]).
size mismatch for roi_head.mask_head.conv_logits.weight: copying a param with shape torch.Size([80, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([4, 256, 1, 1]).
size mismatch for roi_head.mask_head.conv_logits.bias: copying a param with shape torch.Size([80]) from checkpoint, the shape in current model is torch.Size([4]).
`

#This is my configs:

_base_ = '../mask_rcnn/mask-rcnn_r50-caffe_fpn_ms-poly-1x_coco.py'

model = dict(
    roi_head=dict(
        bbox_head=dict(num_classes=4), mask_head=dict(num_classes=4)))

data_root = '/home/mmdetection/data/VOCdevkit/VOC2007_COCO/'
metainfo = {
    'classes': ('plane', 'boat', 'car', 'truck'),
    'palette': [
        (106, 0, 228), (119, 11, 32), (165, 42, 42), (0, 0, 192)
    ]
}
train_dataloader = dict(
    batch_size=1,
    dataset=dict(
        data_root=data_root,
        metainfo=metainfo,
        ann_file='annotations/instances_train2017.json',
        data_prefix=dict(img='train2017/')))
val_dataloader = dict(
    dataset=dict(
        data_root=data_root,
        metainfo=metainfo,
        ann_file='annotations/instances_val2017.json',
        data_prefix=dict(img='val2017/')))
test_dataloader = val_dataloader

val_evaluator = dict(ann_file=data_root + 'annotations/instances_val2017.json')
test_evaluator = val_evaluator

load_from = 'https://download.openmmlab.com/mmdetection/v2.0/mask_rcnn/mask_rcnn_r50_caffe_fpn_mstrain-poly_3x_coco/mask_rcnn_r50_caffe_fpn_mstrain-poly_3x_coco_bbox_mAP-0.408__segm_mAP-0.37_20200504_163245-42aa3d00.pth'

#And this is my CoCo datasets:


{"images": [{"id": 20180000001, "file_name": "000011.jpg", "width": 512, "height": 512}, {"id": 20180000002, "file_name": "000014.jpg", "width": 512, "height": 512}, {"id": 20180000003, "file_name": "000016.jpg", "width": 512, "height": 512}, {"id": 20180000004, "file_name": "000027.jpg", "width": 512, "height": 512}, {"id": 20180000005, "file_name": "000030.jpg", "width": 512, "height": 512}, {"id": 20180000006, "file_name": "000033.jpg", "width": 512, "height": 512}, {"id": 20180000007, "file_name": "000035.jpg", "width": 512, "height": 512}, {"id": 20180000008, "file_name": "000041.jpg", "width": 512, "height": 512}, {"id": 20180000009, "file_name": "000043.jpg", "width": 512, "height": 512}, {"id": 20180000010, "file_name": "000048.jpg", "width": 512, "height": 512}, {"id": 20180000011, "file_name": "000050.jpg", "width": 512, "height": 512}, {"id": 20180000012, "file_name": "000052.jpg", "width": 512, "height": 512}, {"id": 20180000013, "file_name": "000054.jpg", "width": 512, "height": 512}, {"id": 20180000014, "file_name": "000057.jpg", "width": 512, "height": 512}, {"id": 20180000015, "file_name": "000058.jpg", "width": 512, "height": 512}, {"id": 20180000016, "file_name": "000064.jpg", "width": 512, "height": 512}, {"id": 20180000017, "file_name": "000075.jpg", "width": 512, "height": 512}, {"id": 20180000018, "file_name": "000077.jpg", "width": 512, "height": 512}, {"id": 20180000019, "file_name": "000079.jpg", "width": 512, "height": 512}, {"id": 20180000020, "file_name": "000082.jpg", "width": 512, "height": 512}, {"id": 20180000021, "file_name": "000088.jpg", "width": 512, "height": 512}, {"id": 20180000022, "file_name": "000089.jpg", "width": 512, "height": 512}, {"id": 20180000023, "file_name": "000090...........

"annotations": [{"segmentation": [[33, 229, 33, 262, 45, 262, 45, 229]], "area": 396, "iscrowd": 0, "ignore": 0, "image_id": 20180000001, "bbox": [33, 229, 12, 33], "category_id": 8, "id": 1}, {"segmentation": [[142, 94, 142, 106, 160, 106, 160, 94]], "area": 216, "iscrowd": 0, "ignore": 0, "image_id": 20180000001, "bbox": [142, 94, 18, 12], "category_id": 9, "id": 2}, {"segmentation": [[203, 150, 203, 178, 231, 178, 231, 150]], "area": 784, "iscrowd": 0, "ignore": 0, "image_id": 20180000001, "bbox": [203, 150, 28, 28], "category_id": 8, "id": 3}, {"segmentation": [[320, 38, 320, 59, 358, 59, 358, 38]], "area": 798, "iscrowd": 0, "ignore": 0, "image_id": 20180000001, "bbox": [320, 38, 38, 21], "category_id": 8, "id": 4}, {"segmentation": [[381, 33, 381, 52, 413, 52, 413, 33]], "area": 608, "iscrowd": 0, "ignore": 0, "image_id": 20180000001, "bbox": [381, 33, 32, 19], "category_id": 8, "id": 5}, {"segmentation": [[180, 313, 180, 325, 202, 325, 202, 313]], "area": 264, "iscrowd": 0, "ignore": 0, "image_id": 20180000002, "bbox": [180, 313, 22, 12], "category_id": 3, "id": 6}, {"segmentation": [[44, 334, 44, 348, 65, 348, 65, 334]], "area": 294, "iscrowd": 0, "ignore": 0, "image_id": 20180000003, "bbox": [44, 334, 21, 14], "category_id": 3, "id": 7},......

"categories": [{"supercategory": "none", "id": 8, "name": "truck"}, {"supercategory": "none", "id": 9, "name": "boat"}, {"supercategory": "none", "id": 3, "name": "car"}, {"supercategory": "none", "id": 5, "name": "airplane"}]}
tsrobcvai commented 1 year ago

You were trying to train the pre-trained model on your custom dataset. Due to the difference in the number of categories, there would be a size mismatch in the model structure.

ronit450 commented 3 months ago

how to solve this?