open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark

Home Page:https://mmdetection.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Config not reusable for different models

Grushus opened this issue · comments

Hello! I am trying to make a script in python where the mmdetection process automates and up until now I've used retinanet for testing and it's worked fine. But now when I try any other model except retinanet I always get some sort of errors and I think its due to the config file not being reusable. The whole point of mmdetection i believed was to be able to reuse stuff and just change a few variables.

This is my config:

model_config = """
# Inherit and overwrite part of the config based on this config
_base_ = '{model_name}.py'

data_root = '{data_root}'

metainfo = {{
    'classes': {categories}
}}

train_dataloader = dict(
    dataset=dict(
        data_root=data_root,
        metainfo=metainfo,
        data_prefix=dict(img='train/images'),
        ann_file='{train_coco}'))

val_dataloader = dict(
    dataset=dict(
        data_root=data_root,
        metainfo=metainfo,
        data_prefix=dict(img='val/images'),
        ann_file='{val_coco}'))

test_dataloader = dict(
    dataset=dict(
        data_root=data_root,
        metainfo=metainfo,
        data_prefix=dict(img='test/images'),
        ann_file='{test_coco}'))

val_evaluator = dict(ann_file='{val_coco}')

test_evaluator = dict(ann_file='{test_coco}')

model = dict(bbox_head=dict(num_classes={length}))

train_cfg = dict(type='EpochBasedTrainLoop', 
                    max_epochs={max_epochs}, 
                    val_interval={val_interval})

default_hooks = dict(
    checkpoint=dict(
        type="CheckpointHook",
        save_best='{save_best}',
        rule='{rule}',
        interval={checkpoint_interval},
        save_begin={save_begin}
    )
)

# load COCO pre-trained weight
load_from = '{weights_file}'

visualizer = dict(vis_backends=[dict(type='LocalVisBackend'),
                    dict(type='TensorboardVisBackend')])

""".format(model_name = model_name, 
                data_root = data_root,
                train_coco = train_coco,
                test_coco = test_coco,
                val_coco = val_coco,
                categories = categories,
                length = length,
                weights_file = weights_file,
                max_epochs = max_epochs,
                val_interval = val_interval,
                save_best = save_best_checkpoint_metric,
                rule = rule,
                checkpoint_interval = checkpoint_interval,
                save_begin = save_begin)

And all im doing is changing the base variable, and the "load_from" variable. Everything else is the same between runs.
And the only thing this specific config works on is retinanet. Ive tried faster-rcnn, rtmdet, rpn, ssd, centernet. None works, and they all have different errors for not working.

Faster-rcnn for example gives me TypeError: FasterRCNN.__init__() got an unexpected keyword argument 'bbox_head'
Centernet worked halfway but when plotting i got something about x and y not being aligned.

Only thing working is retinanet, which is very unfortunate and I'd appreciate any help i can get.