class_docstr: Detection metric for COCO bbox task.
  
  Parameters
  ----------
  dataset : instance of gluoncv.data.COCODetection
      The validation dataset.
  save_prefix : str
      Prefix for the saved JSON results.
  use_time : bool
      Append unique datetime string to created JSON file name if ``True``.
  cleanup : bool
      Remove created JSON file if ``True``.
  score_thresh : float
      Detection results with confident scores smaller than ``score_thresh`` will
      be discarded before saving to results.
  data_shape : tuple of int, default is None
      If `data_shape` is provided as (height, width), we will rescale bounding boxes when
      saving the predictions.
      This is helpful when SSD/YOLO box predictions cannot be rescaled conveniently. Note that
      the data_shape must be fixed for all validation images.
  post_affine : a callable function with input signature (orig_w, orig_h, out_w, out_h)
      If not None, the bounding boxes will be affine transformed rather than simply scaled.
docstr: Update internal buffer with latest predictions.
  Note that the statistics are not available until you call self.get() to return
  the metrics.
  
  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`.
docstr_tok: ["Update","internal","buffer","with","latest","predictions",".","Note","that","the","statistics","are","not","available","until","you","call","self.get","(",")","to","return","the","metrics",".","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","`","."]
code: def update(
      self, pred_bboxes, pred_labels, pred_scores, *args, **kwargs
  ):
      """Update internal buffer with latest predictions.
      Note that the statistics are not available until you call self.get() to return
      the metrics.
  
      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`.
  
      """
      from ...data.transforms.bbox import affine_transform
  
      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
              ]
              return np.concatenate(out, axis=0)
          elif isinstance(a, mx.nd.NDArray):
              a = a.asnumpy()
          return a
  
      for pred_bbox, pred_label, pred_score in zip(
          *[
              as_numpy(x)
              for x in [pred_bboxes, pred_labels, pred_scores]
          ]
      ):
          valid_pred = np.where(pred_label.flat >= 0)[0]
          pred_bbox = pred_bbox[valid_pred, :].astype(np.float)
          pred_label = pred_label.flat[valid_pred].astype(int)
          pred_score = pred_score.flat[valid_pred].astype(np.float)
  
          imgid = self._img_ids[self._current_id]
          self._current_id += 1
          affine_mat = None
          if self._data_shape is not None:
              entry = self.dataset.coco.loadImgs(imgid)[0]
              orig_height = entry["height"]
              orig_width = entry["width"]
              height_scale = float(orig_height) / self._data_shape[0]
              width_scale = float(orig_width) / self._data_shape[1]
              if self._post_affine is not None:
                  affine_mat = self._post_affine(
                      orig_width,
                      orig_height,
                      self._data_shape[1],
                      self._data_shape[0],
                  )
          else:
              height_scale, width_scale = (1.0, 1.0)
          # for each bbox detection in each image
          for bbox, label, score in zip(
              pred_bbox, pred_label, pred_score
          ):
              if label not in self.dataset.contiguous_id_to_json:
                  # ignore non-exist class
                  continue
              if score < self._score_thresh:
                  continue
              category_id = self.dataset.contiguous_id_to_json[label]
              # rescale bboxes/affine transform bboxes
              if affine_mat is not None:
                  bbox[0:2] = affine_transform(bbox[0:2], affine_mat)
                  bbox[2:4] = affine_transform(bbox[2:4], affine_mat)
              else:
                  bbox[[0, 2]] *= width_scale
                  bbox[[1, 3]] *= height_scale
              # convert [xmin, ymin, xmax, ymax]  to [xmin, ymin, w, h]
              bbox[2:4] -= bbox[:2] - 1
              self._results.append(
                  {
                      "image_id": imgid,
                      "category_id": category_id,
                      "bbox": bbox[:4].tolist(),
                      "score": score,
                  }
              )
  
file_path: gluon-cv/gluoncv/utils/metrics/coco_detection.py
imports: from __future__ import absolute_import
  import sys
  import os
  from os import path
  import warnings
  import numpy
  import mxnet
label_desc: Use image node_id 6 for calling the COCODetectionMetric obj's underlying member method code with example usage: obj.update(pred_bboxes, pred_labels, pred_scores) and returns: a, np