cocodataset / cocoapi

COCO API - Dataset @ http://cocodataset.org/
Other
6.11k stars 3.76k forks source link

Why is it not 1?? #638

Open Li-99 opened 1 year ago

Li-99 commented 1 year ago

Here is my code. However, the result is not 1. def eval_map(ann_json):

with open(ann_json, "r") as f:
    data = json.load(f)
for aa in data["annotations"]:
    aa["score"] = 0.8
with open("try_pre.json", 'w') as output_json_file:
    json.dump(data["annotations"], output_json_file)

coco_gt = COCO(ann_json)
coco_dt = coco_gt.loadRes("try_pre.json")
coco_eval = COCOeval(coco_gt, coco_dt, 'segm')

coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()

################## ann_json: {"categories": [{"id": 1, "name": "binary", "supercategory": "binary"}], "images": [{ "id": 0, "file_name": "test.png", "width": 300, "height": 300}], "annotations": [ {"image_id": 0, "bbox": [100,100,200,200], "category_id": 1, "iscrowd": 0, "area": 10000.0, "id": 0, "segmentation": [[100,100,200,100,200,200,100,200]]}, {"image_id": 0, "bbox": [10,10,30,30], "category_id": 1, "iscrowd": 0, "area": 400.0, "id": 1, "segmentation": [[10,10,30,10,30,30,30,10]]} ]}

try_pre.json: [ {"image_id": 0, "bbox": [100, 100, 200, 200], "category_id": 1, "iscrowd": 0, "area": 10000.0, "id": 0, "segmentation": [[100, 100, 200, 100, 200, 200, 100, 200]], "score": 0.8}, {"image_id": 0, "bbox": [10, 10, 30, 30], "category_id": 1, "iscrowd": 0, "area": 400.0, "id": 1, "segmentation": [[10, 10, 30, 10, 30, 30, 30, 10]], "score": 0.8} ]

THE RESULT: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=1000 ] = 0.000 Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=1000 ] = 0.000 Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=1000 ] = 0.000 Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.000 Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000 Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.000 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=1000 ] = 0.000 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=1000 ] = 0.000 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=1000 ] = 0.000 Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.000 Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = -1.000 Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.000

P1X3LD3M0N commented 1 year ago

It might have to do with the ann_json format. Not sure how to create custom annotation files but this link might help https://www.immersivelimit.com/tutorials/create-coco-annotations-from-scratch/#coco-dataset-format