Mean Average Precision
class MeanAveragePrecision
from_detections
def from_detections(cls, true_batches, detection_batches, num_classes, iou_threshold)
iou_threshold
based on true_batches
and detection_batches
.
Args
-
true_batches:
List[np.ndarray]
representing ground-truth objects across all images in concerned dataset. Each element oftrue_batches
list describe single image and hasshape = (N, 5)
whereN
is number of ground-truth objects. Each row is expected to be in(x_min, y_min, x_max, y_max, class)
. -
detection_batches:
List[np.ndarray]
representing detected objects across all images in concerned dataset. Each element ofdetection_batches
list describe single image and hasshape = (M, 6)
whereM
is number of detected objects. Each row is expected to be in(x_min, y_min, x_max, y_max, class, conf)
. -
num_classes:
int
number of classes detected by model. -
iou_threshold:
float
detection iou threshold between 0 and 1. Detections with lower iou will be classified as FP.
Returns
- mean_average_precision:
MeanAveragePrecision
object containing mAPvalue
calculated for providediou_threshold
as well asAveragePrecision
object calculated for each individual class.
Example usage
>>> import numpy as np
>>> from onemetric.cv.object_detection import MeanAveragePrecision
>>> true_batches = [
... np.array([
... [0.0, 0.0, 3.0, 3.0, 1],
... [2.0, 2.0, 5.0, 5.0, 1],
... [6.0, 1.0, 8.0, 3.0, 2],
... ]),
... np.array([
... [1.0, 1.0, 2.0, 2.0, 2],
... ]),
... ]
>>> detection_batches = [
... np.array([
... [0.0, 0.0, 3.0, 3.0, 1, 0.9],
... [0.1, 0.1, 3.0, 3.0, 0, 0.9],
... [6.0, 1.0, 8.0, 3.0, 1, 0.8],
... [1.0, 6.0, 2.0, 7.0, 1, 0.8],
... ]),
... np.array([
... [1.0, 1.0, 2.0, 2.0, 2, 0.8],
... ]),
... ]
>>> mean_average_precision = MeanAveragePrecision.from_detections(
... true_batches=true_batches,
... detection_batches=detection_batches,
... num_classes=3
... )
>>> mean_average_precision.value
... 0.4444444444444444
plot
def plot(target_path, title, class_names)
Args
-
target_path:
str
selected target location of confusion matrix plot. -
title:
Optional[str]
title displayed at the top of the confusion matrix plot. DefaultNone
. -
class_names:
Optional[List[str]]
list of class names detected my model. If non given class indexes will be used. DefaultNone
.