open-mmlab / mmdetection

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

[Feature] Raise warning or Exception when classes name wrong when using custom classes #9611

Open liuyanyi opened 1 year ago

liuyanyi commented 1 year ago

What's the feature?

I'm trying to train a model with sub set of a dataset in COCO format, so i modify the metadata in the dataset config to Specify the classes to be used.

classes = (
    "row_roof",
    "multiple_eave_roof",
    "hipped_roof_v1",
    "mansard_roof",
    "pyramid_roof",
    "arched_roof",
    "revolved",
    "other"
)

metainfo = {
    'classes': classes,
}
train_dataloader = dict(
    dataset=dict(
        metainfo=metainfo,
    ))

But revolved class is a wrong class name, so in this line https://github.com/open-mmlab/mmdetection/blob/6e9cfd4166840a2dff45aa4134a97b9168177ac3/mmdet/datasets/coco.py#L67-L68 cat_ids only got 7 class ids, which is different from the len(classes). Instances in others be treated as revolved

In mmyolo's analyze script it also got the wrong order of categories, the revolved should be zero and other should be 2872.

The information obtained is as follows:
+-------------------------------+
|  Information of dataset class |
+--------------------+----------+
| Class name         | Bbox num |
+--------------------+----------+
| row_roof           | 943      |
| multiple_eave_roof | 738      |
| hipped_roof_v1     | 4320     |
| mansard_roof       | 510      |
| pyramid_roof       | 1520     |
| arched_roof        | 833      |
| revolved           | 2872     |
| other              | 0        |
+--------------------+----------+

I think there should be an warning or error when len(self.cat_ids) != len(self.metainfo['classes']), or other way to fix that.

What do you guys think? Looking for your suggestions.

Any other context?

No response

hhaAndroid commented 1 year ago

@liuyanyi I think what you said is right, you should tell users clearly. can you fix it?