Hello
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,
})
So what the label map does is it takes the category_id from the annotation and basically uses this to find the proper class name:
the_class_name = dataset.class_names[dataset.label_map[category_id] - 1]
The error indicates that there was a category_id of 12, which was not found in the label map. Looking at the label map you defined, it seems like you skipped 12? Was that intentional? If it was, something may be wrong with your annotations.
Also I noticed in your pascalvoc2012_dataset, you don't have class_names set. You should set it to PASCAL_VOC_CLASSES or else it'll use the COCO class names by default, which will cause a lot of other errors.
And finally, for your yolact_base_config, you do not need to define your own alternative to coco_base_config. Just overwriting dataset and num_classes in yolact_base_config (as you already have done) is enough.
Hello
I effectively forget to set the proper class names.
I inspired the category ids from the one you set for coco in which category id 12 among other is also missing.
Actually this is something that I did not understood why COCO_LABEL_MAP keys start to 1 but finish at 90 ?
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 in COCO_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 to None and it should work.
Ok I understand.
Actually by resetting the PASCAL_LABEL from 1 to 20 and setting properly the PASCAL_VOC_CLASSES
I am now able to do the training :).
Thank you for your help :)
Glad to hear that! Feel free to let me know if you have any other issues.
Hello
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/multipathnetThen I follow the instruction concerning the modification to do in the file _config.py_
But when I call :
python train.py --config=yolact_base_configI 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, })
@JSharp4273 Hello,in order to transfer voc to coco,you mentioned that "pascal_val2012.json"can be downloaded from 'https://github.com/facebookresearch/multipathnet'.
But in this project and links,i cannot find "pascal_val2012.json".
Can you give me specific link for "pascal_val2012.json"?
Many thanks to you.
Hello @jingtingxu369
I retake a look and actually you need to follow the instructions related to the data preparation.
It should be located in:
/multipathnet/data/annotations/pascal_val2012.json
Most helpful comment
Glad to hear that! Feel free to let me know if you have any other issues.