Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'thing_dataset_id_to_contiguous_id' #4574

Open
david95j2 opened this issue Sep 28, 2022 · 1 comment
Open

KeyError: 'thing_dataset_id_to_contiguous_id' #4574

david95j2 opened this issue Sep 28, 2022 · 1 comment
Labels
documentation Problems about existing documentation or comments

Comments

@david95j2
Copy link

david95j2 commented Sep 28, 2022

Hi guys, i am trying to register and train a custom panoptic dataset. I have converted the annotations to coco format.
I have only one concretcrack class and then the following is the format of the panoptic annotations

{
 "info": {...},
 "images": [
    {
      "id": 263,
      "width": 4032,
      "height": 3024,
      "file_name": "000263.jpg"
    }, ...
    ... 
  ],
  "annotations": [
    {
      "image_id": 263,
      "file_name": "000263_GT.png",
      "segments_info": [
        {
          "id": 39372,
          "category_id": 1,
          "bbox": [
            0.0,
            803.0,
            4032.0,
            2221.0
          ],
          "iscrowd": 0,
          "area" : 128846
        }
      ]
    }, ...
    ...
    "categories": [
       {
          "supercateory": "korad",
          "isthing" : 1,
          "id" : 1,
          "name" : "ConcreteCrack",
          "color": [
               0,
              153,
              204
          ]
       }
     ]
}

Instructions To Reproduce the Issue:

from detectron2.data.datasets import register_coco_panoptic, register_coco_panoptic_separated, load_coco_json
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.data.datasets.coco_panoptic import load_coco_panoptic_json

if 'ConcreteCrack' in DatasetCatalog.list():
    DatasetCatalog.remove('ConcreteCrack')

register_coco_panoptic("ConcreteCrack",{},"./datasets/crack/train2022/","./datasets/crack/panoptic_train2022/",
"./datasets/crack/annotations/panoptic_train2022.json","./datasets/crack/annotations/instances_train2022.json")

MetadataCatalog.get("ConcreteCrack").thing_classes = ["ConcreteCrack"]

dicts = load_coco_panoptic_json('./datasets/crack/annotations/panoptic_train2022.json','./datasets/crack/train2022/',
'./datasets/crack/panoptic_train2022/',{})

However I got the following error:

Output exceeds the [size limit](command:workbench.action.openSettings?[). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?9c19538d-6c07-4802-8860-9bb873fd1456)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In [9], line 16
     13 register_coco_panoptic("ConcreteCrack",{},"./datasets/crack/train2022/","./datasets/crack/panoptic_train2022/",
     14 "./datasets/crack/annotations/panoptic_train2022.json","./datasets/crack/annotations/instances_train2022.json")
     15 MetadataCatalog.get("ConcreteCrack").thing_classes = ["ConcreteCrack"]
---> 16 dicts = load_coco_panoptic_json('./datasets/crack/annotations/panoptic_train2022.json','./datasets/crack/train2022/',
     17 './datasets/crack/panoptic_train2022/',{})

File ~/vsc/Mask2Former/seg/lib/python3.8/site-packages/detectron2/data/datasets/coco_panoptic.py:51, in load_coco_panoptic_json(json_file, image_dir, gt_dir, meta)
     49     image_file = os.path.join(image_dir, os.path.splitext(ann["file_name"])[0] + ".jpg")
     50     label_file = os.path.join(gt_dir, ann["file_name"])
---> 51     segments_info = [_convert_category_id(x, meta) for x in ann["segments_info"]]
     52     ret.append(
     53         {
     54             "file_name": image_file,
   (...)
     58         }
     59     )
     60 assert len(ret), f"No images found in {image_dir}!"

File ~/vsc/Mask2Former/seg/lib/python3.8/site-packages/detectron2/data/datasets/coco_panoptic.py:51, in <listcomp>(.0)
     49     image_file = os.path.join(image_dir, os.path.splitext(ann["file_name"])[0] + ".jpg")
     50     label_file = os.path.join(gt_dir, ann["file_name"])
---> 51     segments_info = [_convert_category_id(x, meta) for x in ann["segments_info"]]
...
     29             segment_info["category_id"]
     30         ]
     31         segment_info["isthing"] = True

KeyError: 'thing_dataset_id_to_contiguous_id'

How can i fix the problem? thx :)

@david95j2 david95j2 added the documentation Problems about existing documentation or comments label Sep 28, 2022
@Ahmed-G-ElTaher
Copy link

Ahmed-G-ElTaher commented Nov 24, 2024

@david95j2
How to solve KeyError: 'thing_dataset_id_to_contiguous_id'

Simply try to add classes to metadata brackets it will work

the normal is to write like that :
register_coco_panoptic(
data_name, {} , image_root, panoptic_root, panoptic_json, instances_json=None
)

but to solve it write like this :
register_coco_panoptic(
data_name, {"thing_classes": ["class_1","class_2",…etc.]} , image_root, panoptic_root, panoptic_json, instances_json=None
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Problems about existing documentation or comments
Projects
None yet
Development

No branches or pull requests

2 participants