Context: I am trying to train the VOC dataset on this few shot object detection library called FewX and in order to do that I am using VOC  annotations in the COCO format downloaded from this link (this was available on the COCO website). But I am facing a key error problem when I am running the training script:
This is the part of the code that is raising the key error:
    def generate_support(self, dataset_dict):
        support_way = self.support_way #2
        support_shot = self.support_shot #5
        
        id = dataset_dict['annotations'][0]['id']
        query_cls = self.support_df.loc[self.support_df['id']==id, 'category_id'].tolist()[0] # they share the same category_id and image_id
        query_img = self.support_df.loc[self.support_df['id']==id, 'image_id'].tolist()[0]
        all_cls = self.support_df.loc[self.support_df['image_id']==query_img, 'category_id'].tolist()

and this is the error message
Traceback (most recent call last):
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 149, in train
    self.run_step()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 497, in run_step
    self._trainer.run_step()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 267, in run_step
    data = next(self._data_loader_iter)
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/data/common.py", line 179, in __iter__
    for d in self.dataset:
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in __next__
    data = self._next_data()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
    return self._process_data(data)
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
    data.reraise()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise
    raise self.exc_type(msg)
KeyError: Caught KeyError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/data/common.py", line 43, in __getitem__
    data = self._map_func(self._dataset[cur_idx])
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/utils/serialize.py", line 23, in __call__
    return self._obj(*args, **kwargs)
  File "/home/pranay/repo/FIND-6_v6/fewx/data/dataset_mapper.py", line 110, in __call__
    support_images, support_bboxes, support_cls = self.generate_support(dataset_dict)
  File "/home/pranay/repo/FIND-6_v6/fewx/data/dataset_mapper.py", line 195, in generate_support
    id = dataset_dict['annotations'][0]['id']
KeyError: 'id'

[10/09 00:40:55 d2.engine.hooks]: Total training time: 0:00:00 (0:00:00 on hooks)
[10/09 00:40:55 d2.utils.events]:  iter: 0    lr: N/A  max_mem: 352M
Traceback (most recent call last):
  File "fsod_train_net.py", line 121, in <module>
    launch(
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/launch.py", line 82, in launch
    main_func(*args)
  File "fsod_train_net.py", line 115, in main
    return trainer.train()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 487, in train
    super().train(self.start_iter, self.max_iter)
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 149, in train
    self.run_step()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 497, in run_step
    self._trainer.run_step()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/engine/train_loop.py", line 267, in run_step
    data = next(self._data_loader_iter)
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/data/common.py", line 179, in __iter__
    for d in self.dataset:
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in __next__
    data = self._next_data()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
    return self._process_data(data)
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
    data.reraise()
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise
    raise self.exc_type(msg)
KeyError: Caught KeyError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/data/common.py", line 43, in __getitem__
    data = self._map_func(self._dataset[cur_idx])
  File "/home/pranay/miniconda3/envs/FEWX/lib/python3.8/site-packages/detectron2/utils/serialize.py", line 23, in __call__
    return self._obj(*args, **kwargs)
  File "/home/pranay/repo/FIND-6_v6/fewx/data/dataset_mapper.py", line 110, in __call__
    support_images, support_bboxes, support_cls = self.generate_support(dataset_dict)
  File "/home/pranay/repo/FIND-6_v6/fewx/data/dataset_mapper.py", line 195, in generate_support
    id = dataset_dict['annotations'][0]['id']
KeyError: 'id'

I’ve relooked at the annotations file and they do contain the key ‘id’. I am not sure why is this error popping up. This is a tiny screenshot from the .json file

screenshot1372×232 154 KB

Could anyone please let me know if I am doing anything wrong here?