class_docstr: Computes label and prediction pairs for object detection.
class_docstr_tok: ["Computes","label","and","prediction","pairs","for","object","detection","."]
code: def process(
      self, extracts: types.Extracts
  ) -> Iterator[metric_types.StandardMetricInputs]:
      # stack all the columns of labels and predictions(e.g. xmin, xmax, ymin,
      # ymax, and class_id of bounding boxes) into one single numpy array
      extracts = util.StandardExtracts(extracts)
      if self._labels_to_stack:
          extracts[
              constants.LABELS_KEY
          ] = object_detection_format.stack_labels(
              extracts=extracts,
              col_names=self._labels_to_stack,
              model_name=self._model_name,
              allow_missing_key=self._allow_missing_key,
          )
      if self._predictions_to_stack:
          predictions = object_detection_format.stack_predictions(
              extracts=extracts,
              col_names=self._predictions_to_stack,
              model_name=self._model_name,
              allow_missing_key=self._allow_missing_key,
          )
      else:
          predictions = extracts.get_predictions(
              model_name=self._model_name
          )
  
      if self._num_detections_key and predictions.size:
          predictions = (
              object_detection_format.truncate_by_num_detections(
                  extracts=extracts,
                  num_rows_key=self._num_detections_key,
                  array_to_truncate=predictions,
                  model_name=self._model_name,
                  allow_missing_key=self._allow_missing_key,
              )
          )
  
      extracts[constants.PREDICTIONS_KEY] = predictions
  
      if (
          extracts[constants.LABELS_KEY].ndim != 2
          or extracts[constants.LABELS_KEY].shape[1] <= 4
      ):
          raise ValueError(
              "Raw data of ground truth should be a 2d array of shape "
              "( <batch_size> , 5+), ground truth is "
              f"{extracts[constants.LABELS_KEY]}"
          )
      if (
          extracts[constants.PREDICTIONS_KEY].ndim != 2
          or extracts[constants.PREDICTIONS_KEY].shape[1] <= 5
      ):
          raise ValueError(
              "Raw data of prediction should be a 2d array of shape "
              "( <batch_size> , 6+), prediction is "
              f"{extracts[constants.PREDICTIONS_KEY]}"
          )
      boxes_gt = extracts[constants.LABELS_KEY]
      boxes_pred = bounding_box.sort_boxes_by_confidence(
          extracts[constants.PREDICTIONS_KEY]
      )
      if constants.EXAMPLE_WEIGHTS_KEY in extracts:
          weight = extracts[constants.EXAMPLE_WEIGHTS_KEY]
      else:
          weight = None
  
      (
          labels,
          predictions,
          weights,
      ) = box_match.boxes_to_label_prediction_example_weight(
          boxes_gt=boxes_gt,
          boxes_pred=boxes_pred,
          iou_threshold=self._threshold,
          area_range=self._area_range,
          class_id=self._class_id,
          max_num_detections=self._max_num_detections,
          class_weight=self._class_weight,
          weight=weight,
      )
  
      for l, p, w in zip(labels, predictions, weights):
          result = {}
          result[constants.LABELS_KEY] = [l]
          result[constants.PREDICTIONS_KEY] = [p]
          result[constants.EXAMPLE_WEIGHTS_KEY] = [w]
          yield metric_util.to_standard_metric_inputs(result)
  
file_path: model-analysis/tensorflow_model_analysis/metrics/preprocessors/object_detection_preprocessors.py
imports: from typing import Iterator, List, Optional, Tuple
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.metrics.preprocessors.utils import bounding_box
  from tensorflow_model_analysis.metrics.preprocessors.utils import box_match
  from tensorflow_model_analysis.metrics.preprocessors.utils import object_detection_format
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 2 for calling the BoundingBoxMatchPreprocessor obj's underlying member method code with example usage: obj.process(extracts) without return types