LVIS example

[1]:
import numpy as np
import logging
import faster_coco_eval
from faster_coco_eval import COCO, COCOeval_faster

print(f"{faster_coco_eval.__version__=}")

logging.root.setLevel("INFO")
logging.debug("Запись.")
faster_coco_eval.__version__='1.5.6'
[2]:
prepared_coco_in_dict = COCO.load_json("../tests/lvis_dataset/lvis_val_100.json")
prepared_anns = COCO.load_json("../tests/lvis_dataset/lvis_results_100.json")
[3]:
iouType = "bbox"
[4]:
from lvis import LVISEval

lvis_eval = LVISEval("../tests/lvis_dataset/lvis_val_100.json", "../tests/lvis_dataset/lvis_results_100.json", iouType)
INFO:lvis.lvis:Loading annotations.
INFO:lvis.lvis:Creating index.
INFO:lvis.lvis:Index created.
INFO:lvis.results:Loading and preparing results.
INFO:lvis.results:Creating index.
INFO:lvis.results:Index created.
[5]:
%%time

lvis_eval.evaluate()
INFO:lvis.eval:Running per image evaluation.
INFO:lvis.eval:Evaluate annotation type *bbox*
INFO:lvis.eval:COCOeval_opt._prepare() finished...
INFO:lvis.eval:DONE (t=0.01s).
CPU times: user 766 ms, sys: 32 ms, total: 798 ms
Wall time: 794 ms
[6]:
%%time

lvis_eval.accumulate()
INFO:lvis.eval:Accumulating evaluation results.
CPU times: user 111 ms, sys: 2.12 ms, total: 114 ms
Wall time: 113 ms
[7]:
%%time

lvis_eval.summarize()
CPU times: user 22.5 ms, sys: 21.4 ms, total: 43.8 ms
Wall time: 42.8 ms
[8]:
lvis_eval.print_results()
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=all] = 0.368
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=300 catIds=all] = 0.626
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=300 catIds=all] = 0.384
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=     s | maxDets=300 catIds=all] = 0.301
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=     m | maxDets=300 catIds=all] = 0.438
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=     l | maxDets=300 catIds=all] = 0.447
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=  r] = 0.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=  c] = 0.274
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=  f] = 0.388
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=all] = 0.430
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=     s | maxDets=300 catIds=all] = 0.345
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=     m | maxDets=300 catIds=all] = 0.488
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=     l | maxDets=300 catIds=all] = 0.515
[9]:
cocoGt = COCO(prepared_coco_in_dict)
cocoDt = cocoGt.loadRes(prepared_anns)

cocoEval = COCOeval_faster(cocoGt, cocoDt, iouType, lvis_style=True, print_function=print)
cocoEval.params.maxDets = [300]
[10]:
%%time

cocoEval.evaluate()
Evaluate annotation type *bbox*
COCOeval_opt._prepare() finished...
DONE (t=0.01s).
COCOeval_opt.evaluate() finished...
DONE (t=0.63s).
CPU times: user 581 ms, sys: 53.2 ms, total: 634 ms
Wall time: 631 ms
[11]:
%%time

cocoEval.accumulate()
Accumulating evaluation results...
COCOeval_opt.accumulate() finished...
DONE (t=0.00s).
CPU times: user 42 µs, sys: 20 µs, total: 62 µs
Wall time: 59.6 µs
[12]:
%%time

cocoEval.summarize()
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=all] = 0.368
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=300 catIds=all] = 0.626
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=300 catIds=all] = 0.384
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=300 catIds=all] = 0.301
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=300 catIds=all] = 0.438
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=300 catIds=all] = 0.447
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=  r] = 0.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=  c] = 0.274
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=  f] = 0.388
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=300 catIds=all] = 0.430
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=300 catIds=all] = 0.345
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=300 catIds=all] = 0.488
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=300 catIds=all] = 0.515
 Average Recall     (AR) @[ IoU=0.50      | area=   all | maxDets=300 catIds=all] = 0.720
 Average Recall     (AR) @[ IoU=0.75      | area=   all | maxDets=300 catIds=all] = 0.445
CPU times: user 31.7 ms, sys: 8.7 ms, total: 40.4 ms
Wall time: 39.5 ms