code: def nms(
      bboxes: np.ndarray,
      iou_threshold=0.5,
      soft_threshold=0.3,
      sigma=0.5,
      method="nms",
  ) -> np.ndarray:
      """
      单独对一个类别进行NMS处理
      :param bboxes: [x1, y1, x2, y2, score]
      :param iou_threshold: nms算法中使用到的阈值
      :param soft_threshold: soft-nms算法中使用到的阈值
      :param sigma: soft-nms gaussian sigma
      :param method: nms或者soft-nms
      :return: 返回保留目标的索引
      """
      assert method in ["nms", "soft-nms"]
      # [x1, y1, x2, y2, score] -> [x1, y1, x2, y2, score, index]
      bboxes = np.concatenate(
          [bboxes, np.arange(bboxes.shape[0]).reshape(-1, 1)], axis=1
      )
  
      best_bboxes_index = []
      while len(bboxes) > 0:
          max_ind = np.argmax(bboxes[:, 4])  # 寻找概率最大目标索引
          best_bbox = bboxes[max_ind]
          best_bboxes_index.append(best_bbox[5])
          bboxes = np.concatenate(
              [bboxes[:max_ind], bboxes[max_ind + 1 :]]
          )  # 将最大概率目标去除
          ious = bboxes_iou(best_bbox[np.newaxis, :4], bboxes[:, :4])
  
          if method == "nms":
              iou_mask = np.less(ious, iou_threshold)  # <
          else:  # soft-nms
              weight = np.exp(-(np.square(ious) / sigma))
              bboxes[:, 4] = bboxes[:, 4] * weight
              iou_mask = np.greater(bboxes[:, 4], soft_threshold)  # >
  
          bboxes = bboxes[iou_mask]
  
      return np.array(best_bboxes_index, dtype=np.int32)
  
file_path: deep-learning-for-image-processing/pytorch_object_detection/yolov3_spp/load_onnx_test.py
imports: import time
  import cv2
  import onnx
  import onnxruntime
  import numpy
  from matplotlib import pyplot
  from draw_box_utils import draw_box
label_desc: Use image node_id 7 for calling a global function with example usage: nms(bboxes, iou_threshold, soft_threshold, sigma, method) and returns: np