class_docstr: Calculate mean AP for object detection task
  
  Parameters:
  ---------
  iou_thresh : float
      IOU overlap threshold for TP
  class_names : list of str
      optional, if provided, will print out AP for each class
class_docstr_tok: ["Calculate","mean","AP","for","object","detection","task","Parameters",":","--","--","--","--","-","iou_thresh",":","float","IOU","overlap","threshold","for","TP","class_names",":","list","of","str","optional",",","if","provided",",","will","print","out","AP","for","each","class"]
docstr: Update internal buffer with latest prediction and gt pairs.
  
  Parameters
  ----------
  pred_bboxes : mxnet.NDArray or numpy.ndarray
      Prediction bounding boxes with shape `B, N, 4`.
      Where B is the size of mini-batch, N is the number of bboxes.
  pred_labels : mxnet.NDArray or numpy.ndarray
      Prediction bounding boxes labels with shape `B, N`.
  pred_scores : mxnet.NDArray or numpy.ndarray
      Prediction bounding boxes scores with shape `B, N`.
  gt_bboxes : mxnet.NDArray or numpy.ndarray
      Ground-truth bounding boxes with shape `B, M, 4`.
      Where B is the size of mini-batch, M is the number of ground-truths.
  gt_labels : mxnet.NDArray or numpy.ndarray
      Ground-truth bounding boxes labels with shape `B, M`.
  gt_difficults : mxnet.NDArray or numpy.ndarray, optional, default is None
      Ground-truth bounding boxes difficulty labels with shape `B, M`.
docstr_tok: ["Update","internal","buffer","with","latest","prediction","and","gt","pairs",".","Parameters","--","--","--","--","--","pred_bboxes",":","mxnet.NDArray","or","numpy.ndarray","Prediction","bounding","boxes","with","shape","`","B",",","N",",","4","`",".","Where","B","is","the","size","of","mini-batch",",","N","is","the","number","of","bboxes",".","pred_labels",":","mxnet.NDArray","or","numpy.ndarray","Prediction","bounding","boxes","labels","with","shape","`","B",",","N","`",".","pred_scores",":","mxnet.NDArray","or","numpy.ndarray","Prediction","bounding","boxes","scores","with","shape","`","B",",","N","`",".","gt_bboxes",":","mxnet.NDArray","or","numpy.ndarray","Ground-truth","bounding","boxes","with","shape","`","B",",","M",",","4","`",".","Where","B","is","the","size","of","mini-batch",",","M","is","the","number","of","ground-truths",".","gt_labels",":","mxnet.NDArray","or","numpy.ndarray","Ground-truth","bounding","boxes","labels","with","shape","`","B",",","M","`",".","gt_difficults",":","mxnet.NDArray","or","numpy.ndarray",",","optional",",","default","is","None","Ground-truth","bounding","boxes","difficulty","labels","with","shape","`","B",",","M","`","."]
code: def update(
      self,
      pred_bboxes,
      pred_labels,
      pred_scores,
      gt_bboxes,
      gt_labels,
      gt_difficults=None,
  ):
      """Update internal buffer with latest prediction and gt pairs.
  
      Parameters
      ----------
      pred_bboxes : mxnet.NDArray or numpy.ndarray
          Prediction bounding boxes with shape `B, N, 4`.
          Where B is the size of mini-batch, N is the number of bboxes.
      pred_labels : mxnet.NDArray or numpy.ndarray
          Prediction bounding boxes labels with shape `B, N`.
      pred_scores : mxnet.NDArray or numpy.ndarray
          Prediction bounding boxes scores with shape `B, N`.
      gt_bboxes : mxnet.NDArray or numpy.ndarray
          Ground-truth bounding boxes with shape `B, M, 4`.
          Where B is the size of mini-batch, M is the number of ground-truths.
      gt_labels : mxnet.NDArray or numpy.ndarray
          Ground-truth bounding boxes labels with shape `B, M`.
      gt_difficults : mxnet.NDArray or numpy.ndarray, optional, default is None
          Ground-truth bounding boxes difficulty labels with shape `B, M`.
  
      """
  
      def as_numpy(a):
          """Convert a (list of) mx.NDArray into numpy.ndarray"""
          if isinstance(a, (list, tuple)):
              out = [
                  x.asnumpy() if isinstance(x, mx.nd.NDArray) else x
                  for x in a
              ]
              try:
                  out = np.concatenate(out, axis=0)
              except ValueError:
                  out = np.array(out)
              return out
          elif isinstance(a, mx.nd.NDArray):
              a = a.asnumpy()
          return a
  
      if gt_difficults is None:
          gt_difficults = [None for _ in as_numpy(gt_labels)]
  
      if isinstance(gt_labels, list):
          gt_diff_shape = (
              gt_difficults[0].shape[0]
              if hasattr(gt_difficults[0], "shape")
              else 0
          )
          if (
              len(gt_difficults) * gt_diff_shape
              != len(gt_labels) * gt_labels[0].shape[0]
          ):
              gt_difficults = (
                  [None] * len(gt_labels) * gt_labels[0].shape[0]
              )
  
      for (
          pred_bbox,
          pred_label,
          pred_score,
          gt_bbox,
          gt_label,
          gt_difficult,
      ) in zip(
          *[
              as_numpy(x)
              for x in [
                  pred_bboxes,
                  pred_labels,
                  pred_scores,
                  gt_bboxes,
                  gt_labels,
                  gt_difficults,
              ]
          ]
      ):
          # strip padding -1 for pred and gt
          valid_pred = np.where(pred_label.flat >= 0)[0]
          pred_bbox = pred_bbox[valid_pred, :]
          pred_label = pred_label.flat[valid_pred].astype(int)
          pred_score = pred_score.flat[valid_pred]
          valid_gt = np.where(gt_label.flat >= 0)[0]
          gt_bbox = gt_bbox[valid_gt, :]
          gt_label = gt_label.flat[valid_gt].astype(int)
          if gt_difficult is None:
              gt_difficult = np.zeros(gt_bbox.shape[0])
          else:
              gt_difficult = gt_difficult.flat[valid_gt]
  
          for l in np.unique(
              np.concatenate((pred_label, gt_label)).astype(int)
          ):
              pred_mask_l = pred_label == l
              pred_bbox_l = pred_bbox[pred_mask_l]
              pred_score_l = pred_score[pred_mask_l]
              # sort by score
              order = pred_score_l.argsort()[::-1]
              pred_bbox_l = pred_bbox_l[order]
              pred_score_l = pred_score_l[order]
  
              gt_mask_l = gt_label == l
              gt_bbox_l = gt_bbox[gt_mask_l]
              gt_difficult_l = gt_difficult[gt_mask_l]
  
              self._n_pos[l] += np.logical_not(gt_difficult_l).sum()
              self._score[l].extend(pred_score_l)
  
              if len(pred_bbox_l) == 0:
                  continue
              if len(gt_bbox_l) == 0:
                  self._match[l].extend((0,) * pred_bbox_l.shape[0])
                  continue
  
              # VOC evaluation follows integer typed bounding boxes.
              pred_bbox_l = pred_bbox_l.copy()
              pred_bbox_l[:, 2:] += 1
              gt_bbox_l = gt_bbox_l.copy()
              gt_bbox_l[:, 2:] += 1
  
              iou = bbox_iou(pred_bbox_l, gt_bbox_l)
              gt_index = iou.argmax(axis=1)
              # set -1 if there is no matching ground truth
              gt_index[iou.max(axis=1) < self.iou_thresh] = -1
              del iou
  
              selec = np.zeros(gt_bbox_l.shape[0], dtype=bool)
              for gt_idx in gt_index:
                  if gt_idx >= 0:
                      if gt_difficult_l[gt_idx]:
                          self._match[l].append(-1)
                      else:
                          if not selec[gt_idx]:
                              self._match[l].append(1)
                          else:
                              self._match[l].append(0)
                      selec[gt_idx] = True
                  else:
                      self._match[l].append(0)
  
file_path: gluon-cv/gluoncv/utils/metrics/voc_detection.py
imports: from __future__ import division
  from collections import defaultdict
  import numpy
  import mxnet
  from ..bbox import bbox_iou
label_desc: Use image node_id 4 for calling the VOCMApMetric obj's underlying member method code with example usage: obj.update(pred_bboxes, pred_labels, pred_scores, gt_bboxes, gt_labels, gt_difficults) and returns: a, out