首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Mmdetection检测从自定义COCO数据集加载的错误"-1背景“注释

使用Mmdetection检测从自定义COCO数据集加载的错误"-1背景“注释
EN

Stack Overflow用户
提问于 2021-09-23 04:01:05
回答 1查看 535关注 0票数 0

引言

我正在使用‘m检测来使用自定义COCO数据集来训练一个可变形的DETR模型。意味着使用COCO格式的注释的自定义数据集。dataset使用与COCO相同的图像,为“操场”实验提供了不同的“玩具”注释,并且注释文件是使用pycocotools和json专用包创建的。

我对这个操场数据集做了五个变体:两个有三个类的数据集(类123),一个数据集有六个类(类16),两个数据集有7个类(类17)。

问题

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

代码语言:javascript
复制
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类数据集,结果是非常不同的,其中代码返回以下内容:

代码语言:javascript
复制
{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    |               |       |               |       |               |       |
+---------------+-------+---------------+-------+---------------+-------+---------------+-------+---------------+-------+

代码语言:javascript
复制
{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类数据集的一些类有0的注释,而json显然显示了更多的注释。有没有人遇到过类似的使用Mm检测仪的情况?是什么导致了这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-23 15:47:40

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69293877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档