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:

  • 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 for details.


import paddle.fluid as fluid

import paddle

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

pb ='prior_box', shape=[image_boxs_num, 4],

pbv ='prior_box_var', shape=[image_boxs_num, 4],

loc ='target_box', shape=[batch_size, bounding_bboxes_num, 4],

scores ='scores', shape=[batch_size, bounding_bboxes_num, image_boxs_num],

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

gt_box ="gt_box", shape=[batch_size, 4], dtype="float32")
gt_label ="gt_label", shape=[batch_size, 1], dtype="float32")
difficult ="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

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/ of paddle.fluid.metrics.DetectionMAP.reset, line 3)

Unexpected indentation.

the reset_program.

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/ of paddle.fluid.metrics.DetectionMAP.reset, line 4)

Block quote ends without a blank line; unexpected unindent.


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