ISTR icon indicating copy to clipboard operation
ISTR copied to clipboard

Extracting mAP for each class when evaluating on custom dataset

Open Eldad27 opened this issue 3 years ago • 1 comments

@hujiecpp I am using a custom COCO dataset.

Please is there some way to extract mAP metric for each individual class/label when evaluating?

For example, I have 2 classes of the same object category. How do I address this in code to allow individual class results during inference?

Any help or advice is appreciated, thanks!

Eldad27 avatar May 17 '21 22:05 Eldad27

You can refer to the file detectron2/detectron2/data/datasets/builtin_meta.py, which contains a detailed introduction to the detailed configuration process of the data set. such as: COCO_fomat_your_categories

COCO_CATEGORIES_raw = [
     {"color": [119, 11, 32], "isthing": 1, "id": 1, "name": "bicycle"},
     {"color": [0, 0, 142], "isthing": 1, "id": 2, "name": "car"},
     {"color": [220, 20, 60], "isthing": 1, "id": 3, "name": "person"},
]

_get_coco_instances_meta

def _get_coco_instances_meta(): 
    thing_ids = [k["id"] for k in COCO_CATEGORIES_raw if k["isthing"] == 1] 
    thing_colors = [k["color"] for k in COCO_CATEGORIES_raw if k["isthing"] == 1]
    assert len(thing_ids) == 3, len(thing_ids)
    # Mapping from the incontiguous COCO category id to an id in [0, 79]
    thing_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(thing_ids)}
    thing_classes = [k["name"] for k in COCO_CATEGORIES_raw if k["isthing"] == 1]
    #print("_get_coco_instances_meta thing_classes:", thing_classes)
    '''
    _get_coco_instances_meta thing_classes: ['bicycle', 'car', 'person']
    '''
    ret = {
        "thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id,
        "thing_classes": thing_classes,
        "thing_colors": thing_colors,
    }
    
    print("ret:", ret)
    '''
    ret = {'thing_dataset_id_to_contiguous_id': {1: 0, 2: 1, 3: 2}, 'thing_classes': ['bicycle', 'car', 'person'], 'thing_colors': [[119, 11, 32], [0, 0, 142], [220, 20, 60]]}
    '''
    return ret

You will get the evaluate results like: image

luyao-cv avatar May 18 '21 09:05 luyao-cv