code: def post_process(pred: np.ndarray, multi_label=False, conf_thres=0.3):
      """
      输入的xywh都是归一化后的值
      :param pred: [num_obj, [x1, y1, x2, y2, objectness, cls1, cls1...]]
      :param img_size:
      :param multi_label:
      :param conf_thres:
      :return:
      """
      min_wh, max_wh = 2, 4096
      pred = pred[pred[:, 4] > conf_thres]  # 虑除小objectness目标
      pred = pred[
          ((pred[:, 2:4] > min_wh) & (pred[:, 2:4] < max_wh)).all(1)
      ]  # 虑除规定尺度范围外的目标
  
      if pred.shape[0] == 0:
          return np.empty((0, 6))  # [x, y, x, y, score, class]
  
      box = xywh2xyxy(pred[:, :4])
      # Detections matrix nx6 (xyxy, conf, cls)
      if multi_label:  # 针对每个类别执行非极大值抑制
          # i, j = (x[:, 5:] > conf_thres).nonzero().t()
          # x = torch.cat((box[i], x[i, j + 5].unsqueeze(1), j.float().unsqueeze(1)), 1)
          pass
      else:  # best class only  直接针对每个类别中概率最大的类别进行非极大值抑制处理
          objectness = pred[:, 5:]
          class_index = np.argmax(objectness, axis=1)
          conf = objectness[(np.arange(pred.shape[0]), class_index)]
          # conf, j = predictions[:, 5:].max(1)
          pred = np.concatenate(
              (
                  box,
                  np.expand_dims(conf, axis=1),
                  np.expand_dims(class_index, axis=1),
              ),
              1,
          )[conf > conf_thres]
  
      n = pred.shape[0]  # number of boxes
      if n == 0:
          return np.empty((0, 6))  # [x, y, x, y, score, class]
  
      cls = pred[:, 5]  # classes
      boxes, scores = (
          pred[:, :4] + cls.reshape(-1, 1) * max_wh,
          pred[:, 4:5],
      )
      t1 = time.time()
      indexes = nms(np.concatenate([boxes, scores], axis=1))
      print("NMS time is {}".format(time.time() - t1))
      pred = pred[indexes]
  
      return pred
  
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 8 for calling a global function with example usage: post_process(pred, multi_label, conf_thres) and returns: pred, np, np