DetectionMAP

class paddle.fluid.metrics.DetectionMAP(input, gt_label, gt_box, gt_difficult=None, class_num=None, background_label=0, overlap_threshold=0.5, evaluate_difficult=True, ap_version='integral')[source]

Calculate the detection mean average precision (mAP).

The general steps are as follows:

  1. calculate the true positive and false positive according to the input of detection and labels.

  2. calculate mAP value, support two versions: ‘11 point’ and ‘integral’. 11point: the 11-point interpolated average precision. integral: the natural integral of the precision-recall curve.

Please get more information from the following articles:

Parameters
  • input (Variable) – LoDTensor, The detection results, which is a LoDTensor with shape [M, 6]. The layout is [label, confidence, xmin, ymin, xmax, ymax]. The data type is float32 or float64.

  • gt_label (Variable) – LoDTensor, The ground truth label index, which is a LoDTensor with shape [N, 1].The data type is float32 or float64.

  • gt_box (Variable) – LoDTensor, The ground truth bounding box (bbox), which is a LoDTensor with shape [N, 4]. The layout is [xmin, ymin, xmax, ymax]. The data type is float32 or float64.

  • gt_difficult (Variable|None) – LoDTensor, Whether this ground truth is a difficult bounding bbox, which can be a LoDTensor [N, 1] or not set. If None, it means all the ground truth labels are not difficult bbox.The data type is int.

  • class_num (int) – The class number.

  • background_label (int) – The index of background label, the background label will be ignored. If set to -1, then all categories will be considered, 0 by default.

  • overlap_threshold (float) – The threshold for deciding true/false positive, 0.5 by default.

  • evaluate_difficult (bool) – Whether to consider difficult ground truth for evaluation, True by default. This argument does not work when gt_difficult is None.

  • ap_version (str) – The average precision calculation ways, it must be ‘integral’ or ‘11point’. Please check https://sanchom.wordpress.com/tag/average-precision/ for details.

Examples

import paddle.fluid as fluid

batch_size = None # can be any size
image_boxs_num = 10
bounding_bboxes_num = 21

pb = fluid.data(name='prior_box', shape=[image_boxs_num, 4],
           dtype='float32')

pbv = fluid.data(name='prior_box_var', shape=[image_boxs_num, 4],
             dtype='float32')

loc = fluid.data(name='target_box', shape=[batch_size, bounding_bboxes_num, 4],
            dtype='float32')

scores = fluid.data(name='scores', shape=[batch_size, bounding_bboxes_num, image_boxs_num],
                dtype='float32')

nmsed_outs = fluid.layers.detection_output(scores=scores,
    loc=loc, prior_box=pb, prior_box_var=pbv)

gt_box = fluid.data(name="gt_box", shape=[batch_size, 4], dtype="float32")
gt_label = fluid.data(name="gt_label", shape=[batch_size, 1], dtype="float32")
difficult = fluid.data(name="difficult", shape=[batch_size, 1], dtype="float32")

exe = fluid.Executor(fluid.CUDAPlace(0))
map_evaluator = fluid.metrics.DetectionMAP(nmsed_outs, gt_label, gt_box, difficult, class_num = 3)

cur_map, accum_map = map_evaluator.get_map_var()
get_map_var()
Returns: mAP variable of current mini-batch and

accumulative mAP variable cross mini-batches.

reset(executor, reset_program=None)

Reset metric states at the begin of each pass/user specified batch. :param executor: a executor for executing

the reset_program.

Parameters

reset_program (Program|None) – a single Program for reset process. If None, will create a Program.