open-mmlab / mmdetection

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

CocoDataset may not support `metainfo` through config file. #10949

Open ZhangYouyi opened 11 months ago

ZhangYouyi commented 11 months ago

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the Prepare a config and prepared a customized object detection dataset.
  3. The bug has not been fixed in the 3.0.0 version.

Describe the bug mmdet.datasets.coco.CocoDataset may not support metainfo through config file.

Reproduction

  1. Add metainfo config in config file referring to Prepare a config.
  2. Run the following test case.
config_file = ''
cfg = Config.fromfile(config_file)
runner = Runner.from_cfg(cfg)
runner.train()

Environment

sys.platform: linux Python: 3.7.3 CUDA available: True TorchVision: 0.13.0+cu116 OpenCV: 4.5.5 MMEngine: 0.7.3 MMDetection: 3.0.0+

Error traceback

1 2

echonax07 commented 11 months ago

yes i think you are right

i am defined my metainfo in config file and pass

metainfo = { 'classes': ('whale',), } and

train_dataloader = dict(
    batch_size=1,
    num_workers=2,
    persistent_workers=True,
    # sampler=dict(type='Balanced_sampler', shuffle=True),
    sampler=dict(type='DefaultSampler', shuffle=True),
    batch_sampler=dict(type='AspectRatioBatchSampler'),
    dataset=dict(
        type=dataset_type,
        # data_root=data_root,
        data_root='/media/pc2041/data/vip_lab/whale/whale_data/balanced_sampler/',
        metainfo=metainfo,
        ann_file='train.json',
        data_prefix=dict(img='./'),
        filter_cfg=dict(filter_empty_gt=False, min_size=32),
        pipeline=train_pipeline,
        backend_args=backend_args))

now when I inspect the dataset instance using VSCODE debugger I get the following

image

ZhangYouyi commented 11 months ago

In MMDetection-3.0.0, to solve this problem temporarily, we can override CocoDataset as the following python snippet

@DATASETS.register_module()
class CustomDataset(CocoDataset):
    """Customized Dataset for COCO detection format."""

    METAINFO = {
        'classes': (
            'a', 'b', 'c'
        )
    }

, and update dataset type to be CustomDataset in the corresponding config file.

WangChen100 commented 6 months ago

@ZhangYouyi When I evaluate mmdet on my custom dataset as same format as COCO, I have the same problem which leads to"out of range" error in line 243 of coco_metric.py.

Although cocoapi is initialized by the specific annotation file, but its metainfo is still as same as coco, i.e. 80 classes.

In MMDetection-3.3.0, it can be solved by set "metainfo" in the config file as follow: 微信截图_20240229151741

leoromanovich commented 5 months ago

I'm not sure if this the common case, but with that approach inference with config like that is not working as expected (wrt to class indexes). To get the proper class_id:class_name map I've had to take my coco_annotations.json, get categories from that and -1 to all categories.