:mod:`blueoil.metrics.mean_average_precision` ============================================= .. py:module:: blueoil.metrics.mean_average_precision Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: blueoil.metrics.mean_average_precision.average_precision blueoil.metrics.mean_average_precision._streaming_tp_fp_array blueoil.metrics.mean_average_precision._average_precision blueoil.metrics.mean_average_precision._safe_div_zeros blueoil.metrics.mean_average_precision._safe_div_ones blueoil.metrics.mean_average_precision._precision_recall blueoil.metrics.mean_average_precision._cummax blueoil.metrics.mean_average_precision._mean_average_precision blueoil.metrics.mean_average_precision._boxes_in_the_class blueoil.metrics.mean_average_precision._tp_and_fp blueoil.metrics.mean_average_precision.tp_fp_in_the_image blueoil.metrics.mean_average_precision._calc_precision_recall blueoil.metrics.mean_average_precision._calc_average_precision blueoil.metrics.mean_average_precision._calc_overlap .. function:: average_precision(num_gt_boxes, tp, fp, score, class_name, metrics_collections=None, updates_collections=None) Compute average precision. :param num_gt_boxes: a scalar tensor. number of gt boxes. :type num_gt_boxes: tf.Tensor :param tp: tp vector. elements are int or bool. :type tp: tf.Tensor :param fp: fp vector. elements are int or bool. :type fp: tf.Tensor :param score: score vector. :type score: tf.Tensor :param class_name: class_name :type class_name: str :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. :rtype: average precision(tf.Tensor) .. function:: _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. .. function:: _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/ .. function:: _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` .. function:: _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` .. function:: _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 .. function:: _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`. .. function:: _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)] :type all_predict_boxes: list :param all_gt_boxes: ground truth boxes. shape is [num_images, num_max_gt_boxes, 5(x, y, w, h, class)] :type all_gt_boxes: numpy.ndarray :param classes: classes list. :param overlap_thresh: threshold of overlap. :returns: dictionary include 'MeanAveragePrecision' 'AveragePrecision', 'Precision', 'Recall', 'OrderedPrecision', 'OrderedRecall', 'OrderedMaxedPrecision' .. function:: _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. :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)] :type all_predict_boxes: list :param all_gt_boxes: ground truth boxes. shape is [num_images, num_max_gt_boxes, 5(x, y, w, h, class)] :type all_gt_boxes: numpy.ndarray :param class_index: index of classes. :type class_index: int :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)] :rtype: pred_boxes_in_the_class_list(list) .. function:: _tp_and_fp(class_pred_boxes, class_gt_boxes, overlap_thresh) Calculate tp and fp in the classes. :param pred_boxes_in_the_class_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)] :type pred_boxes_in_the_class_list: list :param gt_boxes_in_the_class_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)] :type gt_boxes_in_the_class_list: list :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. :rtype: tps(np.ndarray) .. function:: tp_fp_in_the_image(pred_boxes, gt_boxes, overlap_thresh) Calculate tp and fp in the image. :param pred_boxes: predicted boxes in the image. shape is [num_pred_boxes, 6(x, y, w, h, class, scores)] :type pred_boxes: numpy.ndarray :param gt_boxes: ground truth boxes in the image. shape is [num_gt_boxes, 5(x, y, w, h, class)] :type gt_boxes: numpy.ndarray :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. :rtype: tp(numpy.ndarray) .. function:: _calc_precision_recall(tp, fp, num_gt_boxes) Calculate precision and recall array. :param tp: sorted tp. :type tp: np.ndarray :param fp: sorted fp. :type fp: np.ndarray :param num_gt_boxes: number of gt boxes :type num_gt_boxes: int :returns: detection boxes size precision array recall: detection boxes size recall array scalar_precision: precision scalar_recall: recall :rtype: precision .. function:: _calc_average_precision(precision, recall) .. function:: _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: