code: def greedy_nmm(
      object_predictions_as_tensor: torch.tensor,
      match_metric: str = "IOU",
      match_threshold: float = 0.5,
  ):
      """
      Apply greedy version of non-maximum merging to avoid detecting too many
      overlapping bounding boxes for a given object.
      Args:
          object_predictions_as_tensor: (tensor) The location preds for the image
              along with the class predscores, Shape: [num_boxes,5].
          object_predictions_as_list: ObjectPredictionList Object prediction objects
              to be merged.
          match_metric: (str) IOU or IOS
          match_threshold: (float) The overlap thresh for
              match metric.
      Returns:
          keep_to_merge_list: (Dict[int:List[int]]) mapping from prediction indices
          to keep to a list of prediction indices to be merged.
      """
      keep_to_merge_list = {}
  
      # we extract coordinates for every
      # prediction box present in P
      x1 = object_predictions_as_tensor[:, 0]
      y1 = object_predictions_as_tensor[:, 1]
      x2 = object_predictions_as_tensor[:, 2]
      y2 = object_predictions_as_tensor[:, 3]
  
      # we extract the confidence scores as well
      scores = object_predictions_as_tensor[:, 4]
  
      # calculate area of every block in P
      areas = (x2 - x1) * (y2 - y1)
  
      # sort the prediction boxes in P
      # according to their confidence scores
      order = scores.argsort()
  
      # initialise an empty list for
      # filtered prediction boxes
      keep = []
  
      while len(order) > 0:
          # extract the index of the
          # prediction with highest score
          # we call this prediction S
          idx = order[-1]
  
          # push S in filtered predictions list
          keep.append(idx.tolist())
  
          # remove S from P
          order = order[:-1]
  
          # sanity check
          if len(order) == 0:
              keep_to_merge_list[idx.tolist()] = []
              break
  
          # select coordinates of BBoxes according to
          # the indices in order
          xx1 = torch.index_select(x1, dim=0, index=order)
          xx2 = torch.index_select(x2, dim=0, index=order)
          yy1 = torch.index_select(y1, dim=0, index=order)
          yy2 = torch.index_select(y2, dim=0, index=order)
  
          # find the coordinates of the intersection boxes
          xx1 = torch.max(xx1, x1[idx])
          yy1 = torch.max(yy1, y1[idx])
          xx2 = torch.min(xx2, x2[idx])
          yy2 = torch.min(yy2, y2[idx])
  
          # find height and width of the intersection boxes
          w = xx2 - xx1
          h = yy2 - yy1
  
          # take max with 0.0 to avoid negative w and h
          # due to non-overlapping boxes
          w = torch.clamp(w, min=0.0)
          h = torch.clamp(h, min=0.0)
  
          # find the intersection area
          inter = w * h
  
          # find the areas of BBoxes according the indices in order
          rem_areas = torch.index_select(areas, dim=0, index=order)
  
          if match_metric == "IOU":
              # find the union of every prediction T in P
              # with the prediction S
              # Note that areas[idx] represents area of S
              union = (rem_areas - inter) + areas[idx]
              # find the IoU of every prediction in P with S
              match_metric_value = inter / union
  
          elif match_metric == "IOS":
              # find the smaller area of every prediction T in P
              # with the prediction S
              # Note that areas[idx] represents area of S
              smaller = torch.min(rem_areas, areas[idx])
              # find the IoS of every prediction in P with S
              match_metric_value = inter / smaller
          else:
              raise ValueError()
  
          # keep the boxes with IoU/IoS less than thresh_iou
          mask = match_metric_value < match_threshold
          matched_box_indices = order[
              (mask == False).nonzero().flatten()
          ].flip(dims=(0,))
          unmatched_indices = order[(mask == True).nonzero().flatten()]
  
          # update box pool
          order = unmatched_indices[scores[unmatched_indices].argsort()]
  
          # create keep_ind to merge_ind_list mapping
          keep_to_merge_list[idx.tolist()] = []
  
          for matched_box_ind in matched_box_indices.tolist():
              keep_to_merge_list[idx.tolist()].append(matched_box_ind)
  
      return keep_to_merge_list
  
imports: import logging
  from typing import List
  import torch
  from sahi.postprocess.utils import ObjectPredictionList, has_match, merge_object_prediction_pair
  from sahi.prediction import ObjectPrediction
  from sahi.utils.import_utils import check_requirements
label_desc: Use image node_id 4 for calling a global function with example usage: greedy_nmm(object_predictions_as_tensor, match_metric, match_threshold) and returns: keep_to_merge_list