KeyError while trying to retrain on Pascal
See original GitHub issueHello
I am facing a little issue. I am trying to retrain the model on Pascal Voc 2012 dataset. I took the coco like annotations from this source: https://github.com/facebookresearch/multipathnet
Then I follow the instruction concerning the modification to do in the file config.py
But when I call : python train.py --config=yolact_base_config
I receive the following error:
KeyError: 'Traceback (most recent call last):\n File "/home/smile/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop\n samples = collate_fn([dataset[i] for i in batch_indices])\n File "/home/smile/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 138, in <listcomp>\n samples = collate_fn([dataset[i] for i in batch_indices])\n File "/hdd1/prog/yolact/data/coco.py", line 88, in __getitem__\n im, gt, masks, h, w, num_crowds = self.pull_item(index)\n File "/hdd1/prog/yolact/data/coco.py", line 145, in pull_item\n target = self.target_transform(target, width, height)\n File "/hdd1/prog/yolact/data/coco.py", line 39, in __call__\n label_idx = self.label_map[obj[\'category_id\']] - 1\nKeyError: 12\n'
The error is quite not clear to me.
So what I did is create a new dataset:
PASCAL_VOC_CLASSES = ("aeroplane", "bicycle", "bird", "boat", "bottle",
"bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant",
"sheep", "sofa", "train", "tvmonitor")
PASCAL_VOC_LABEL_MAP = { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8,
9: 9, 10: 10, 11: 11, 13: 12, 14: 13, 15: 14, 16: 15, 17: 16,
18: 17, 19: 18, 20: 19, 21: 20}
pascalvoc2012_dataset = dataset_base.copy({
'name': 'PASCAL VOC 2012',
'train_images':'/media/smile/45C142AD782A7053/Datasets/PASCAL_VOC/VOC2012/VOCdevkit/VOC2012/JPEGImages/',
'train_info':'/home/smile/multipathnet/data/annotations/pascal_train2012.json',
'valid_images':'/media/smile/45C142AD782A7053/Datasets/PASCAL_VOC/VOC2012/VOCdevkit/VOC2012/JPEGImages/',
'valid_info':'/home/smile/multipathnet/data/annotations/pascal_val2012.json',
'label_map': PASCAL_VOC_LABEL_MAP
})
I created a new base_config that only which call the dataset I previously created with the proper number of classes:
pascalvoc_base_config = Config({
'dataset': pascalvoc2012_dataset,
'num_classes': 21, # This should include the background class
...
All the other fields are let untouch.
Finally I adapted yolact_base_config:
#yolact_base_config = coco_base_config.copy({
yolact_base_config = pascalvoc_base_config.copy({
'name': 'yolact_base',
# Dataset stuff
# 'dataset': coco2017_dataset,
# 'num_classes': len(coco2017_dataset.class_names) + 1,
'dataset': pascalvoc2012_dataset,
'num_classes': len(pascalvoc2012_dataset.class_names) + 1,
Here also all the other fields are let untouch.
EDIT
After applying the modifications discussed here the dataset configuration in order to train Pascal Voc is:
MEANS_PV = (103.17, 111.70, 116.69)
STD_PV = (61.11, 59.89, 61.00)
PASCAL_VOC_CLASSES = ("aeroplane", "bicycle", "bird", "boat", "bottle",
"bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant",
"sheep", "sofa", "train", "tvmonitor")
PASCAL_VOC_LABEL_MAP = { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8,
9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16,
17: 17, 18: 18, 19: 19, 20: 20}
pascalvoc2012_dataset = dataset_base.copy({
'name': 'PASCAL VOC 2012',
'train_images':'/media/smile/45C142AD782A7053/Datasets/PASCAL_VOC/VOC2012/VOCdevkit/VOC2012/JPEGImages/',
'train_info':'/home/smile/multipathnet/data/annotations/pascal_train2012.json',
'valid_images':'/media/smile/45C142AD782A7053/Datasets/PASCAL_VOC/VOC2012/VOCdevkit/VOC2012/JPEGImages/',
'valid_info':'/home/smile/multipathnet/data/annotations/pascal_val2012.json',
'label_map': PASCAL_VOC_LABEL_MAP,
'class_names': PASCAL_VOC_CLASSES,
})
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
The reason for COCO_LABEL_MAP to exist is because the category ids in COCO aren’t sequential. During development they removed some classes (there were originally 90) but kept the IDs the same, so while for instance
toothbrush
is the 80th element inCOCO_CLASSES
, in the annotations it’s actually category_id 90. Thus for COCO, that map is necessary to get from category_id to index in the class_names list. For most datasets without that kind of issue, it can be omitted (set to None, which will load the identity map; i.e., x maps to x).So I don’t think you need a label_map at all. Just set
label_map
toNone
and it should work.Glad to hear that! Feel free to let me know if you have any other issues.