This repo is a drop-in replacement for cocoapi to calculate F-beta scores for object detection tasks.
cd PythonAPI && make
OR
pip3 install 'git+https://github.com/yhsmiley/fdet-api.git#subdirectory=PythonAPI'
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
cocoGt = COCO(true_path) # initialize COCO ground truth api
cocoDt = cocoGt.loadRes(pred_path) # initialize COCO prediction api
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox') # initialize COCO evaluation api
cocoEval.evaluate()
cocoEval.accumulateFBeta()
Get best F-beta score for specific iou threshold and class (optional):
fscore, conf, precision, recall = cocoEval.getBestFBeta(beta=1, iouThr=0.5, classIdx=None, average='macro')
cocoEval.summarizeFBetaScores(average='macro')
cocoEval.printReport(beta=1, iouThr=0.5)
cocoEval.plotFBetaCurve(filename, betas=[1,2], iouThr=0.5, average='macro')
cocoEval.plotPRCurve(filename, average='macro')
Edge cases:
- no ground truths, and no detections for the class: TP=FP=FN=0 -> precision, recall, F1 = 1
- ground truth exists, but no detections for the class: TP=FP=0, FN>0 -> precision = 1
cocoEval.accumulate()
cocoEval.summarize()
mapAll, map50 = cocoEval.stats[:2]
cocoEval.plotCocoPRCurve(filename, classIdx=None)
- Vectorize
_getFBetaScore()
- Add option for micro/macro/weighted Fscores for
_getFBetaScore()
- Combine similar functions
- Plot FBetaCurve per class