【问题标题】:Wrong "-1 background" annotations loaded from Custom COCO Dataset using Mmdetection使用 Mmdetection 从自定义 COCO 数据集加载错误的“-1 背景”注释
【发布时间】:2021-09-23 04:01:05
【问题描述】:

简介

我正在使用 Mmdetection 使用自定义 COCO 数据集训练可变形 DETR 模型。意思是使用 COCO 格式注释的自定义数据集。该数据集使用与 COCO 相同的图像,具有不同的“玩具”注释,用于“游乐场”实验,并且注释文件是使用包 pycocotools 和 json 专门创建的。

我对这个 Playground 数据集做了五种变体:2 个数据集包含三个类(类 123),1 个数据集包含六个类(类 16)和2 个数据集,包含 7 个类别(类别 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-classes 数据集和 6-classes 数据集之一,结果非常不同,此代码返回以下内容:

{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清楚地显示了更多。有没有人使用 Mmdetection 遇到过类似的事情?什么可能导致此问题?

【问题讨论】:

    标签: python pytorch object-detection


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 2019-10-03
      • 2019-02-21
      • 1970-01-01
      • 2023-02-24
      • 1970-01-01
      • 2022-09-27
      相关资源
      最近更新 更多