open-mmlab / mmdetection

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

KeyError: '`cfg` or `default_args` must contain the key "type", but got {\'roi_head\': {\'bbox_head\': {\'num_classes\': 1}, \'mask_head\': {\'num_classes\': 1}}}\nNone' #10330

Open yogurtbuddy opened 1 year ago

yogurtbuddy commented 1 year ago

how to fix it? here are my code ps(my dataset just have one jpg and the num-classes just only one)

新配置继承了基本配置,并做了必要的修改

base = 'E:\github\mmdetection-main\mmdetection-main\configs\cascade_rcnn/cascade-mask-rcnn_r50_fpn_1x_coco.py'

我们还需要更改 head 中的 num_classes 以匹配数据集中的类别数

model = dict( delete=True, roi_head=dict( bbox_head=dict(num_classes=1), mask_head=dict(num_classes=1)))

修改数据集相关配置

data_root = 'E:\github\VOC2007/' metainfo = { 'classes': ('wk', ), 'palette': [ (220, 20, 60), ] } train_dataloader = dict( batch_size=1, dataset=dict( data_root=data_root, metainfo=metainfo, ann_file='train/final.json', data_prefix=dict(img='train/'))) val_dataloader = dict( dataset=dict( data_root=data_root, metainfo=metainfo, ann_file='val/final3.json', data_prefix=dict(img='val/'))) test_dataloader = val_dataloader

修改评价指标相关配置

val_evaluator = dict(ann_file=data_root + 'val/final3.json') test_evaluator = val_evaluator

使用预训练的 Mask R-CNN 模型权重来做初始化,可以提高模型性能

load_from = 'E:/github/dataset/cascade_mask_rcnn_r50_fpn_mstrain_3x_coco_20210628_164719-5bdc3824.pth'

yogurtbuddy commented 1 year ago

image

yogurtbuddy commented 1 year ago

i figure out where is wrong but still not know how to fix it image

yogurtbuddy commented 1 year ago

if i delete the code"delete=True,",it would be like this: 1684155481373

zhongyas commented 1 year ago

I also encountered this problem. Have you solved it now?

YOODS-Xu commented 7 months ago

@yogurtbuddy @zhongyas 我在CO-DETR时,也遇到了同样的错误。如果您已经解决,敬请赐教是如何解决的。

YOODS-Xu commented 7 months ago

@yogurtbuddy @zhongyas 我发现当要继承的是list, 就会继承不全,下例的roi_head和bbox_head,在生成的最终config文件里除了num_classes以外,其他信息都被屏蔽掉了。 而直接的dict()就能继承全部信息,下例的query_head,除了num_classes其他信息都还保留。

但是我不知道如何解决list的继承问题,希望各路英雄能够赐教。

my_config model = dict( query_head=dict(num_classes=1,), roi_head=[dict(bbox_head=dict(num_classes=1,),),], bbox_head=[dict(num_classes=1,),])

final config bbox_head=[ dict(num_classes=1), ],

2315455002 commented 1 week ago

I also encountered this problem. Have you solved it now?

YOODS-Xu commented 1 week ago

@2315455002 I could not solve it, and give up.