简介
我正在使用Mmdetection来使用自定义COCO数据集训练可变形DETR模型。表示使用COCO注解格式的自定义数据集。该数据集使用与COCO相同的图像,具有不同的“玩具”注解用于“Playground”实验,并且注解文件仅使用pycocotools和json包创建。
我对这个Playground数据集做了五个变化:2个数据集有3个类(类1
、2
和3
),1个数据集有6个类(类1
到6
),2个数据集有7个类(类1
到7
)。
问题
现在,在使用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 | | |
+----------+-------+------------+-------+----------+-------+---------------+-------+----------+-------+
你可以看到在注解json中没有“-1”id,而且来自3-classes数据集的一些类有0个注解,而json清楚地显示了更多。有人在使用MmmDetection时遇到过类似的情况吗?是什么导致了这个问题?
1条答案
按热度按时间elcex8rz1#
注解文件中的类名与mmdetection配置对象中的类名不匹配。纠正这些问题就解决了。