kwcoco.metrics.voc_metrics module¶
- class kwcoco.metrics.voc_metrics.VOC_Metrics(classes=None)[source]¶
Bases:
NiceRepr
API to compute object detection scores using Pascal VOC evaluation method.
To use, add true and predicted detections for each image and then run the
VOC_Metrics.score()
function.- Variables
recs (Dict[int, List[dict]]) – true boxes for each image. maps image ids to a list of records within that image. Each record is a tlbr bbox, a difficult flag, and a class name.
cx_to_lines (Dict[int, List]) – VOC formatted prediction preditions. mapping from class index to all predictions for that category. Each “line” is a list of [[<imgid>, <score>, <tl_x>, <tl_y>, <br_x>, <br_y>]].
classes (None | List[str] | kwcoco.CategoryTree) – class names
- score(iou_thresh=0.5, bias=1, method='voc2012')[source]¶
Compute VOC scores for every category
Example
>>> from kwcoco.metrics.detect_metrics import DetectionMetrics >>> from kwcoco.metrics.voc_metrics import * # NOQA >>> dmet = DetectionMetrics.demo( >>> nimgs=1, nboxes=(0, 100), n_fp=(0, 30), n_fn=(0, 30), classes=2, score_noise=0.9, newstyle=0) >>> gid = ub.peek(dmet.gid_to_pred_dets) >>> self = VOC_Metrics(classes=dmet.classes) >>> self.add_truth(dmet.true_detections(gid), gid) >>> self.add_predictions(dmet.pred_detections(gid), gid) >>> voc_scores = self.score() >>> # xdoctest: +REQUIRES(--show) >>> import kwplot >>> kwplot.autompl() >>> kwplot.figure(fnum=1, doclf=True) >>> voc_scores['perclass'].draw(key='pr')
kwplot.figure(fnum=2) dmet.true_detections(0).draw(color=’green’, labels=None) dmet.pred_detections(0).draw(color=’blue’, labels=None) kwplot.autoplt().gca().set_xlim(0, 100) kwplot.autoplt().gca().set_ylim(0, 100)