open-mmlab / mmdetection

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

[BUG] TypeError: MaskRCNN: __init__() got an unexpected keyword argument 'bbox_head' #9746

Closed lwttttt closed 1 year ago

lwttttt commented 1 year ago

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

master branch https://github.com/open-mmlab/mmdetection

Environment

torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1

Reproduces the problem - code sample

I just use my own configs which inherited the '/mask_rcnn/mask_rcnn_r50_fpn_mstrain-poly_3x_coco.py'

Reproduces the problem - command or script

here is the code: base = ['/mask_rcnn/mask_rcnn_r50_fpn_mstrain-poly_3x_coco.py'] model = dict( bbox_head=dict(num_classes=1)) dataset_type ='COCODataset' classes = ('balloon',) data = dict( samples_per_gpu=32, workers_per_gpu=2, train = dict( type = 'COCODataset', ann_file = '../data/ballon/train/via_region_data.json', img_prefix = '../data/ballon/train' ), val = dict( type = 'COCODataset', image_prefix = '../data/ballon/val', ann_file = '../data/ballon/val/via_region_data.json' )

Reproduces the problem - error message

test_cfg=cfg.get('test_cfg')) File "/data/run01/scz0ach/openmmlab1/mmdetection-master/mmdet/models/builder.py", line 59, in build_detector cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg)) File "/HOME/scz0ach/.conda/envs/openmmlab1/lib/python3.7/site-packages/mmcv/utils/registry.py", line 237, in build return self.build_func(*args, **kwargs, registry=self) File "/HOME/scz0ach/.conda/envs/openmmlab1/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/HOME/scz0ach/.conda/envs/openmmlab1/lib/python3.7/site-packages/mmcv/utils/registry.py", line 72, in build_from_cfg raise type(e)(f'{obj_cls.name}: {e}') TypeError: MaskRCNN: init() got an unexpected keyword argument 'bbox_head'

Additional information

No response

RangiLyu commented 1 year ago

MaskRCNN has no bbox_head. It is a two stage detector and your config should be like this:

model = dict(
    roi_head=dict(bbox_head=dict(num_classes=1)))

please refer to configs/_base_/models/mask-rcnn_r50_fpn.py

lwttttt commented 1 year ago

however, I just quote and inherited the base file offered by this project(why there is this error?)

RangiLyu commented 1 year ago

however, I just quote and inherited the base file offered by this project(why there is this error?)

image Because you write the bbox_head config in the wrong place. Mask R-CNN does not have bbox_head, its roi_head does.

lwttttt commented 1 year ago

however, I just quote and inherited the base file offered by this project(why there is this error?)

image Because you write the bbox_head config in the wrong place. Mask R-CNN does not have bbox_head, its roi_head does.

thank you so much!!! ♥♥♥