code: def boxes_to_label_prediction_example_weight(
      boxes_gt: np.ndarray,
      boxes_pred: np.ndarray,
      class_id: int,
      iou_threshold: float,
      area_range: Optional[Tuple[float, float]] = (0, float("inf")),
      max_num_detections: Optional[int] = None,
      class_weight: Optional[float] = None,
      weight: Optional[float] = None,
      match_boxes_func: Optional[
          Callable[
              [np.ndarray, Union[float, Iterable[float]]],
              Tuple[np.ndarray, np.ndarray],
          ]
      ] = None,
      iou_func: Optional[
          Callable[[np.ndarray, np.ndarray], np.ndarray]
      ] = None,
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
      """Generate label prediction weight tuple from ground truths and detections.
  
      Args:
       boxes_gt: a numpy array representing the bounding boxes in the following
         format [LEFT, TOP, RIGHT, BOTTOM, CLASS]
       boxes_pred: a numpy array representing the bounding boxes in the following
         format [LEFT, TOP, RIGHT, BOTTOM, CLASS, CONFIDENCE]
       class_id: the class to consider classification.
       iou_threshold: the threshold for two bounding boxes to be considered as a
         Match.
       area_range: objects outside of this arange will be excluded.
       max_num_detections: maximum number of detections in a single image.
       class_weight: the weight associated with this class.
       weight: weight of this image/example.
       match_boxes_func: optional alternative function to compute match_boxes.
       iou_func: optional alternative function to compute box ious.
  
      Returns:
       (label, prediction, weight): three lists of numpy array for binary
       classfication.
      """
      # Sanity check of the dimension and shape of inputs
      if (
          len(boxes_gt.shape) != 2
          or boxes_gt.shape[1] != 5
          or len(boxes_pred.shape) != 2
          or boxes_pred.shape[1] != 6
      ):
          raise ValueError(
              "Input boxes list should be a 2d array of shape ( ,5)"
              "for ground truth and ( ,6) for prediction, where"
              f"boxes_gt.shape = {boxes_gt.shape}, "
              f"boxes_pred.shape = {boxes_pred.shape}"
          )
      if max_num_detections is not None and max_num_detections <= 0:
          raise ValueError(
              f"max_num_detections = {max_num_detections} must be positive."
          )
      if class_id < 0:
          raise ValueError(
              f"class_id = {class_id} must be 0 or positive."
          )
      if class_weight is not None and class_weight < 0.0:
          raise ValueError(
              f"class_weight = {class_weight} must be 0 or positive."
          )
  
      # Filter all bounding boxes with a specific Class
      boxes_gt = bounding_box.filter_boxes_by_class(
          boxes_gt, [class_id]
      )
      boxes_pred = bounding_box.filter_boxes_by_class(
          boxes_pred, [class_id]
      )
  
      # Filter ground truth bounding boxes within an area range
      boxes_gt = bounding_box.filter_boxes_by_area_range(
          boxes_gt, area_range
      )
  
      # Sort predictions with confidence(larger ones first)
      boxes_pred = bounding_box.sort_boxes_by_confidence(boxes_pred)
  
      # Limit detection numbers to max_num_detections
      if (max_num_detections is not None) and (
          boxes_pred.shape[0] > max_num_detections
      ):
          boxes_pred = boxes_pred[:max_num_detections]
  
      if not iou_func:
          iou_func = compute_ious_for_image
      ious = iou_func(boxes_pred[:, :CLASS], boxes_gt[:, :CLASS])
      if not match_boxes_func:
          match_boxes_func = _match_boxes
      matches_gt, matches_pred = match_boxes_func(ious, iou_threshold)
  
      # It is assumed that it only takes one iou_threshold result while it
      # returns a list of results, so the matches only needs to take the first
      # entry of the results
      matches_gt = matches_gt[0]
      matches_pred = matches_pred[0]
  
      # Ignore the unmatched predictions which is out of the area range
      boxes_pred_area_tag = bounding_box.check_boxes_in_area_range(
          boxes_pred, area_range
      )
      # Only count unmatched predictions within the area range
      boxes_pred_num_unmatched = np.count_nonzero(
          boxes_pred_area_tag & (matches_pred == -1)
      )
  
      # If the index is -1, it means unmatched
      labels = np.append(
          np.ones(boxes_gt.shape[0]), np.zeros(boxes_pred_num_unmatched)
      )
  
      predictions = np.concatenate(
          (
              boxes_pred[matches_gt[matches_gt != -1], CONFIDENCE],
              np.zeros(np.count_nonzero((matches_gt == -1))),
              boxes_pred[
                  boxes_pred_area_tag & (matches_pred == -1), CONFIDENCE
              ],
          )
      )
  
      if weight is None:
          weight = 1.0
      if class_weight is None:
          class_weight = 1.0
      weights = np.ones_like(labels) * weight * class_weight
  
      return (labels, predictions, weights)
  
imports: from typing import Callable, Iterable, Union, Tuple, Optional
  import numpy
  from tensorflow_model_analysis.metrics.preprocessors.utils import bounding_box
label_desc: Use image node_id 3 for calling a global function with example usage: boxes_to_label_prediction_example_weight(boxes_gt, boxes_pred, class_id, iou_threshold, area_range, max_num_detections, class_weight, weight, match_boxes_func, iou_func) and returns: labels,  predictions,  weights