dbolya / tide

A General Toolbox for Identifying Object Detection Errors
https://dbolya.github.io/tide
MIT License
702 stars 115 forks source link

Dataset which is not COCO in COCO format #9

Closed toddChavezz closed 3 years ago

toddChavezz commented 3 years ago

Is it possible to apply TIDE as it is to a custom dataset which is not COCO but is in the exact format of COCO? My model also outputs the same results file. But at the moment I get:

Traceback (most recent call last): File "..../mAP_evaluation.py", line 91, in evaluate_coco tide.summarize() File "..../lib/python3.7/site-packages/tidecv/quantify.py", line 494, in summarize main_errors = self.get_main_errors() File "..../lib/python3.7/site-packages/tidecv/quantify.py", line 603, in get_main_errors for error, value in run.fix_main_errors().items() File "..../lib/python3.7/site-packages/tidecv/quantify.py", line 349, in fix_main_errors new_ap = _ap_data.get_mAP() File "...../lib/python3.7/site-packages/tidecv/ap.py", line 150, in get_mAP return sum(aps) / len(aps) ZeroDivisionError: division by zero

Thanks a lot in advance!

reubenwenisch commented 2 years ago

@toddChavezz were you able to do this successfully?

toddChavezz commented 2 years ago

I borrowed the solution from my dear colleague @leonvarga . Call below functions like this:

            tide = TIDE()
            tide.evaluate(coco_gt_to_tide_data(coco_true), coco_dt_to_tide_data(coco_pred), mode=TIDE.BOX)
            tide.summarize()

The functions:

from tidecv import Data, f
from pycocotools.coco import COCO

def coco_gt_to_tide_data(coco_gt: COCO, name="default"):
    data = Data(name)

    for idx, image in enumerate(coco_gt.imgs.values()):
        if 'file_name' in image.keys():
            data.add_image(image['id'], image['file_name'])

    if coco_gt.cats is not None:
        for cat in coco_gt.cats.values():
            if 'name' in cat.keys():
                data.add_class(cat['id'], cat['name'])

    for ann in coco_gt.anns.values():
        image = ann['image_id']
        _cls = ann['category_id']
        box = ann['bbox']

        if ann['iscrowd']:
            data.add_ignore_region(image, _cls, box)
        else:
            data.add_ground_truth(image, _cls, box)

    return data

def coco_dt_to_tide_data(coco_dt: COCO, name="default"):
    data = Data(name)

    for det in coco_dt.anns.values():
        image = det['image_id']
        _cls = det['category_id']
        score = det['score']
        box = det['bbox'] if 'bbox' in det else None
        mask = det['segmentation'] if 'segmentation' in det else None

        data.add_detection(image, _cls, score, box, mask)

    return data