Skip to content

core.services.model.evaluator.utils.compute_confusion_matrix

compute_confusion_matrix

Functions:

Name Description
box_iou

Calculate intersection-over-union (IoU) of boxes. Both sets of boxes are expected to be in (x1, y1, x2, y2) format.

compute_full_confusion_matrix

Compute a confusion matrix for object detection with a background class.

compute_confusion_matrix_impl

box_iou(box1, box2, eps=1e-07)

Calculate intersection-over-union (IoU) of boxes. Both sets of boxes are expected to be in (x1, y1, x2, y2) format. Based on https://github.com/pytorch/vision/blob/master/torchvision/ops/boxes.py.

Parameters:

Name Type Description Default

box1

Tensor

A tensor of shape (N, 4) representing N bounding boxes.

required

box2

Tensor

A tensor of shape (M, 4) representing M bounding boxes.

required

eps

float

A small value to avoid division by zero. Defaults to 1e-7.

1e-07

Returns:

Type Description
Tensor

An NxM tensor containing the pairwise IoU values for every element in box1 and box2.

compute_full_confusion_matrix(gt_annotations, pred_annotations, label_map, iou_threshold=0.5)

Compute a confusion matrix for object detection with a background class.

Parameters:

Name Type Description Default

gt_annotations

List[dict]

Ground truth annotations from COCO GT (coco.loadAnns()).

required

pred_annotations

List[dict]

Predicted annotations from COCO Pred (coco.loadAnns()).

required

label_map

dict

Mapping of category indices (as int) to class names.

required

iou_threshold

float

IoU threshold for matching.

0.5

Returns:

Type Description
ndarray

np.ndarray: Confusion matrix of shape (num_classes+1, num_classes+1) where the last index represents 'background'.

compute_confusion_matrix_impl(coco_gt, coco_pred, label_map, training_labelmap, experiment_logger)