Documentation for detection_utils.metrics¶
compute_precision(prediction_detections, …) |
Compute the average precision of predictions given targets. |
compute_recall(prediction_detections, …) |
Compute the average recall of predictions given targets. |
-
detection_utils.metrics.compute_precision(prediction_detections: numpy.ndarray, truth_detections: numpy.ndarray, threshold: float = 0.5) → float[source]¶ Compute the average precision of predictions given targets.
Precision is defined as the number of true positive predictions divided by the number of total positive predictions.
Parameters: prediction_detections : numpy.ndarray, shape=(N, 5)
The predicted objects, in (left, top, right, bottom, class) format.
truth_detections : numpy.ndarray, shape=(K, 5)
The ground-truth objects in (left, top, right, bottom, class) format.
threshold : Real, optional (default=0.5)
The IoU threshold at which to compute precision.
Returns: float
The average precision (AP) for the given detections and truth.
Notes
This function operates such that when there are zero predictions, precision is 1.
Examples
>>> from detection_utils.metrics import compute_precision >>> import numpy as np >>> predictions = np.array([[0, 0, 10, 10, 1], [3, 3, 7, 7, 1]]) # left, top, right, bottom, class prediction >>> actual = np.array([[2, 3, 6, 7, 1]]) >>> compute_precision(predictions, actual) 0.5
# Our IoUs are 0.16, 0.6 >>> compute_precision(predictions, actual, threshold=0.15) 1.0
>>> compute_precision(predictions, actual, threshold=0.75) 0.0
-
detection_utils.metrics.compute_recall(prediction_detections: numpy.ndarray, truth_detections: numpy.ndarray, threshold: float = 0.5) → float[source]¶ Compute the average recall of predictions given targets.
Recall is defined as the number true positive predictions divided by the number of ground-truth targets.
Parameters: prediction_detections : numpy.ndarray, shape=(N, 5)
The predicted objects, in (left, top, right, bottom, class) format.
truth_detections : numpy.ndarray, shape=(K, 5)
The ground-truth objects in (left, top, right, bottom, class) format.
threshold : Real, optional (default=0.5)
The IoU threshold at which to compute recall.
Returns: float
The average recall (AR) for the given detections and truth.
Notes
This function operates such that when there are zero targets, recall is 1 regardless of predictions.
Examples
>>> from detection_utils.metrics import compute_recall >>> import numpy as np >>> predictions = np.array([[0, 0, 10, 10, 1], [3, 3, 7, 7, 1]]) # left, top, right, bottom, class prediction >>> actual = np.array([[2, 3, 6, 7, 1]]) >>> compute_recall(predictions, actual) 1.0
# Our highest IoU is 0.6 so let’s set our threshold above that >>> compute_recall(predictions, actual, threshold=0.75) 0.0