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: 'id' #69

Open
Maojianzeng opened this issue Apr 27, 2022 · 1 comment
Open

KeyError: 'id' #69

Maojianzeng opened this issue Apr 27, 2022 · 1 comment

Comments

@Maojianzeng
Copy link

Maojianzeng commented Apr 27, 2022

When I apply the FewX on custom dataset, I meet an error:

Traceback (most recent call last):
File "/root/FewX-master/fsod_train_net.py", line 323, in
launch(
File "/root/.local/lib/python3.9/site-packages/detectron2/engine/launch.py", line 62, in launch
main_func(*args)
File "/root/FewX-master/fsod_train_net.py", line 317, in main
return trainer.train()
File "/root/.local/lib/python3.9/site-packages/detectron2/engine/defaults.py", line 431, in train
super().train(self.start_iter, self.max_iter)
File "/root/.local/lib/python3.9/site-packages/detectron2/engine/train_loop.py", line 138, in train
self.run_step()
File "/root/.local/lib/python3.9/site-packages/detectron2/engine/defaults.py", line 441, in run_step
self._trainer.run_step()
File "/root/.local/lib/python3.9/site-packages/detectron2/engine/train_loop.py", line 226, in run_step
data = next(self._data_loader_iter)
File "/root/.local/lib/python3.9/site-packages/detectron2/data/common.py", line 179, in iter
for d in self.dataset:
File "/opt/conda/envs/pytorch1.8/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 517, in next
data = self._next_data()
File "/opt/conda/envs/pytorch1.8/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 557, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/opt/conda/envs/pytorch1.8/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/opt/conda/envs/pytorch1.8/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/root/.local/lib/python3.9/site-packages/detectron2/data/common.py", line 43, in getitem
data = self._map_func(self._dataset[cur_idx])
File "/root/.local/lib/python3.9/site-packages/detectron2/utils/serialize.py", line 23, in call
return self._obj(*args, **kwargs)
File "/root/FewX-master/fewx/data/dataset_mapper.py", line 123, in call
support_images, support_bboxes, support_cls = self.generate_support(dataset_dict)
File "/root/FewX-master/fewx/data/dataset_mapper.py", line 208, in generate_support
id = dataset_dict['annotations'][0]['id']
KeyError: 'id'

I print the dataset_dict as follow:

{'file_name': 'datasets/my_data/support/train2017/9838da66b7ca2606a418900fd6c33f34.jpg', 'height': 800, 'width': 800, 'annotations': [{'iscrowd': 0, 'bbox': [38, 40, 109, 141], 'category_id': 5, 'bbox_mode': <BoxMode.XYWH_ABS: 1>}, {'iscrowd': 0, 'bbox': [466, 391, 15, 29], 'category_id': 5, 'bbox_mode': <BoxMode.XYWH_ABS: 1>}]}

In dataset_dict['annotations'], there is no item called 'id', but in my json file the 'id' is included.

{"height": 800, "width": 800, "id": 635, "file_name": "9838da66b7ca2606a418900fd6c33f34.jpg"}
{"id": 1554, "image_id": 635, "category_id": 6, "segmentation": [[38, 40, 38, 110.5, 38, 181, 92.5, 181, 147, 181, 147, 110.5, 147, 40, 92.5, 40]], "bbox": [38, 40, 109, 141], "iscrowd": 0, "area": 15620}, {"id": 1555, "image_id": 635, "category_id": 6, "segmentation": [[466, 391, 466, 405.5, 466, 420, 473.5, 420, 481, 420, 481, 405.5, 481, 391, 473.5, 391]], "bbox": [466, 391, 15, 29], "iscrowd": 0, "area": 480},

Would you please explain why there is no 'id' in the dataset_dict['annotations']?

@JeremyWangK
Copy link

I have the same problem, have you solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants