# 8.1.1.6.1.1. blueoil.metrics.mean_average_precision¶

## 8.1.1.6.1.1.1. Module Contents¶

### 8.1.1.6.1.1.1.1. Functions¶

 average_precision(num_gt_boxes, tp, fp, score, class_name, metrics_collections=None, updates_collections=None) Compute average precision. _streaming_tp_fp_array(num_gt_boxes, tp, fp, scores, class_name, remove_zero_scores=True, metrics_collections=None, updates_collections=None, name=None) Streaming computation of True Positive and False Positive arrays. This metrics _average_precision(precision, recall, name=None) Compute (interpolated) average precision from precision and recall array Tensors. _safe_div_zeros(numerator, denominator, name) Divides two values, returning 0 if the denominator is <= 0. _safe_div_ones(numerator, denominator, name) Divides two values, returning 1 if the denominator is <= 0. _precision_recall(tp, fp, scores, num_gt_boxes, class_name, dtype=tf.float64, scope=None) Compute precision and recall from scores, true positives and false _cummax(x, reverse=False, name=None) Compute the cumulative maximum of the tensor x along axis. This _mean_average_precision(all_predict_boxes, all_gt_boxes, classes, overlap_thresh=0.5) Calcurate mean average precision. _boxes_in_the_class(all_predict_boxes, all_gt_boxes, class_index) Get pred_boxes and gt_boxes in a class to make it easy to be calculated precision, rec all and so on. _tp_and_fp(class_pred_boxes, class_gt_boxes, overlap_thresh) Calculate tp and fp in the classes. tp_fp_in_the_image(pred_boxes, gt_boxes, overlap_thresh) Calculate tp and fp in the image. _calc_precision_recall(tp, fp, num_gt_boxes) Calculate precision and recall array. _calc_average_precision(precision, recall) _calc_overlap(gt_boxes, pred_box) Calcurate overlap
blueoil.metrics.mean_average_precision.average_precision(num_gt_boxes, tp, fp, score, class_name, metrics_collections=None, updates_collections=None)

Compute average precision.

Parameters
• num_gt_boxes (tf.Tensor) – a scalar tensor. number of gt boxes.

• tp (tf.Tensor) – tp vector. elements are int or bool.

• fp (tf.Tensor) – fp vector. elements are int or bool.

• score (tf.Tensor) – score vector.

• class_name (str) – class_name

Returns

scalar presicion_array(tf.Tensor): vector of presicion. recall_array(tf.Tensor): vector of recall. presicion(tf.Tensor): scalr of presicion. recall(tf.Tensor): scalar of recall.

Return type

average precision(tf.Tensor)

blueoil.metrics.mean_average_precision._streaming_tp_fp_array(num_gt_boxes, tp, fp, scores, class_name, remove_zero_scores=True, metrics_collections=None, updates_collections=None, name=None)

Streaming computation of True Positive and False Positive arrays. This metrics also keeps track of scores and number of grountruth objects.

blueoil.metrics.mean_average_precision._average_precision(precision, recall, name=None)

Compute (interpolated) average precision from precision and recall array Tensors. The implementation follows Pascal 2012 and ILSVRC guidelines. See also: https://sanchom.wordpress.com/tag/average-precision/

blueoil.metrics.mean_average_precision._safe_div_zeros(numerator, denominator, name)

Divides two values, returning 0 if the denominator is <= 0. :param numerator: A real Tensor. :param denominator: A real Tensor, with dtype matching numerator. :param name: Name for the returned op.

Returns

0 if denominator <= 0, else numerator / denominator

blueoil.metrics.mean_average_precision._safe_div_ones(numerator, denominator, name)

Divides two values, returning 1 if the denominator is <= 0. :param numerator: A real Tensor. :param denominator: A real Tensor, with dtype matching numerator. :param name: Name for the returned op.

Returns

1 if denominator <= 0, else numerator / denominator

blueoil.metrics.mean_average_precision._precision_recall(tp, fp, scores, num_gt_boxes, class_name, dtype=tf.float64, scope=None)

Compute precision and recall from scores, true positives and false positives booleans arrays

blueoil.metrics.mean_average_precision._cummax(x, reverse=False, name=None)

Compute the cumulative maximum of the tensor x along axis. This operation is similar to the more classic cumsum. Only support 1D Tensor for now. Args: x: A Tensor. Must be one of the following types: float32, float64,

int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half. axis: A Tensor of type int32 (default: 0). reverse: A bool (default: False). name: A name for the operation (optional).

Returns: A Tensor. Has the same type as x.

blueoil.metrics.mean_average_precision._mean_average_precision(all_predict_boxes, all_gt_boxes, classes, overlap_thresh=0.5)

Calcurate mean average precision. :param all_predict_boxes: python list of numpy.ndarray. all images predicted boxes.

all_pred_boxes[image_index] shape is [num_pred_boxes, 6(x, y, w, h, class, scores)]

Parameters
• all_gt_boxes (numpy.ndarray) – ground truth boxes. shape is [num_images, num_max_gt_boxes, 5(x, y, w, h, class)]

• classes – classes list.

• overlap_thresh – threshold of overlap.

Returns

dictionary include ‘MeanAveragePrecision’ ‘AveragePrecision’, ‘Precision’, ‘Recall’, ‘OrderedPrecision’, ‘OrderedRecall’, ‘OrderedMaxedPrecision’

blueoil.metrics.mean_average_precision._boxes_in_the_class(all_predict_boxes, all_gt_boxes, class_index)

Get pred_boxes and gt_boxes in a class to make it easy to be calculated precision, rec all and so on.

Parameters
• all_predict_boxes (list) – python list of numpy.ndarray. all images predicted boxes. all_pred_boxes[image_index] shape is [num_pred_boxes, 6(x, y, w, h, class, scores)]

• all_gt_boxes (numpy.ndarray) – ground truth boxes. shape is [num_images, num_max_gt_boxes, 5(x, y, w, h, class)]

• class_index (int) – index of classes.

Returns

predicted boxes in the class.

pred_boxes_in_the_class_list[image_index] shape is [num_pred_boxes, 6(x, y, w, h, class, scores)]

gt_boxes_in_the_class_list(list): ground truth boxes in the class.

gt_boxes_in_the_class_list[image_index] shape is [num_gt_boxes, 5(x, y, w, h, class)]

Return type

pred_boxes_in_the_class_list(list)

blueoil.metrics.mean_average_precision._tp_and_fp(class_pred_boxes, class_gt_boxes, overlap_thresh)

Calculate tp and fp in the classes.

Parameters
• pred_boxes_in_the_class_list (list) – predicted boxes in the class. pred_boxes_in_the_class_list[image_index] shape is [num_pred_boxes, 6(x, y, w, h, class, scores)]

• gt_boxes_in_the_class_list (list) – ground truth boxes in the class. gt_boxes_in_the_class_list[image_index] shape is [num_gt_boxes, 5(x, y, w, h, class)]

Returns

prediction boxes length vector of tp sorted by score. fps(np.ndarray): prediction boxes length vector of fp sorted by score. num_gt_boxes(int): number of gt boxes.

Return type

tps(np.ndarray)

blueoil.metrics.mean_average_precision.tp_fp_in_the_image(pred_boxes, gt_boxes, overlap_thresh)

Calculate tp and fp in the image.

Parameters
• pred_boxes (numpy.ndarray) – predicted boxes in the image. shape is [num_pred_boxes, 6(x, y, w, h, class, scores)]

• gt_boxes (numpy.ndarray) – ground truth boxes in the image. shape is [num_gt_boxes, 5(x, y, w, h, class)]

Returns

prediction boxes length vector of tp. fp(numpy.ndarray): prediction boxes length vector of fp. score(numpy.ndarray): prediction boxes length vector of score.

Return type

tp(numpy.ndarray)

blueoil.metrics.mean_average_precision._calc_precision_recall(tp, fp, num_gt_boxes)

Calculate precision and recall array.

Parameters
• tp (np.ndarray) – sorted tp.

• fp (np.ndarray) – sorted fp.

• num_gt_boxes (int) – number of gt boxes

Returns

detection boxes size precision array recall: detection boxes size recall array scalar_precision: precision scalar_recall: recall

Return type

precision

blueoil.metrics.mean_average_precision._calc_average_precision(precision, recall)
blueoil.metrics.mean_average_precision._calc_overlap(gt_boxes, pred_box)

Calcurate overlap :param gt_boxes: ground truth boxes in the image. shape is [num_boxes, 5(x, y, w, h, class)] :param pred_box: a predict box in the image. shape is [6(x, y, w, h, class, prob)]

Return: