使用毫米检测从自定义 COCO 数据集加载错误的"-1 background"注释



简介

我正在使用Mmtdetection来使用自定义的COCO数据集训练可变形的DETR模型。意味着使用注释的COCO格式的自定义数据集。数据集使用与COCO相同的图像;玩具;用于";操场;实验和注释文件是专门使用pycocotools和json包创建的。

我对这个操场数据集进行了五种变体:两个数据集有三个类(类123),一个数据集只有六个类(类别16),还有两个数据集中有七个类(类型17)。

问题

现在,在使用mmdet.datasets.build_dataset在mmdetection中创建数据集之后,我使用以下代码来检查是否一切正常:

from pycocotools.coco import COCO
from os import path as osp
from mmdet.datasets import build_dataset
cfg = start_config() # this is simply a function to startup the config file
ann_file = osp.join(cfg.data.train.data_root, cfg.data.train.ann_file)
coco = COCO(ann_file)
img_ids = coco.getImgIds()
ann_ids = coco.getAnnIds(imgIds=img_ids)
anns = coco.loadAnns(ids=ann_ids)
cats_counter = {}
for ann in anns:
if ann['category_id'] in cats_counter:
cats_counter[ann['category_id']]+=1
else:
cats_counter[ann['category_id']] = 1
print(cats_counter)
cats = {cat['id']:cat for cat in coco.loadCats(coco.getCatIds())}
for i in range(len(cats_counter)):
print("{} ({}) t|t{}".format(i, cats[i]['name'], cats_counter[i]))
ds = build_dataset(cfg.data.train)
print(ds)

对于其中三个数据集,json文件和构建的mmdet数据集的数量几乎完全相等。然而,对于3类数据集和6类数据集中的一个,结果相差甚远,其中此代码返回以下内容:

{3: 1843, 1: 659, 4: 1594, 2: 582, 0: 1421, 5: 498}
0 (1)   |   1421
1 (2)   |   659
2 (3)   |   582
3 (4)   |   1843
4 (5)   |   1594
5 (6)   |   498
loading annotations into memory...
Done (t=0.06s)
creating index...
index created!
CocoDataset Train dataset with number of images 1001, and instance counts: 
+---------------+-------+---------------+-------+---------------+-------+---------------+-------+---------------+-------+
| category      | count | category      | count | category      | count | category      | count | category      | count |
+---------------+-------+---------------+-------+---------------+-------+---------------+-------+---------------+-------+
| 0 [1]         | 1421  | 1 [2]         | 659   | 2 [3]         | 581   | 3 [4]         | 1843  | 4 [5]         | 1594  |
|               |       |               |       |               |       |               |       |               |       |
| 5 [6]         | 0     | -1 background | 45    |               |       |               |       |               |       |
+---------------+-------+---------------+-------+---------------+-------+---------------+-------+---------------+-------+

{1: 1420, 0: 4131, 2: 1046}
0 (1)   |   4131
1 (2)   |   1420
2 (3)   |   1046
loading annotations into memory...
Done (t=0.06s)
creating index...
index created!
CocoDataset Train dataset with number of images 1001, and instance counts: 
+----------+-------+------------+-------+----------+-------+---------------+-------+----------+-------+
| category | count | category   | count | category | count | category      | count | category | count |
+----------+-------+------------+-------+----------+-------+---------------+-------+----------+-------+
|          |       |            |       |          |       |               |       |          |       |
| 0 [1]    | 1419  | 1 [2]      | 0     | 2 [3]    | 0     | -1 background | 443   |          |       |
+----------+-------+------------+-------+----------+-------+---------------+-------+----------+-------+

你可以看到-1〃;注释json中的id,以及3-classes数据集中的一些类都有0个注释,而json显然显示了更多的注释。有人在使用Mmtdetection时遇到过类似的情况吗?是什么原因导致了这个问题?

注释文件中的类名与mmdetection配置对象中的类名不匹配。纠正这些问题解决了问题。