code: def main():
      img_size = 512
      save_path = "yolov3spp.onnx"
      img_path = "test.jpg"
      input_size = (img_size, img_size)  # h, w
  
      # check onnx model
      onnx_model = onnx.load(save_path)
      onnx.checker.check_model(onnx_model)
      # print(onnx.helper.printable_graph(onnx_model.graph))
      ort_session = onnxruntime.InferenceSession(save_path)
  
      img_o = cv2.imread(img_path)  # BGR
      assert img_o is not None, "Image Not Found " + img_path
  
      # preprocessing img
      img, ratio, pad = scale_img(
          img_o, new_shape=input_size, auto=False, color=(0, 0, 0)
      )
      # Convert
      img = img[:, :, ::-1].transpose(
          2, 0, 1
      )  # BGR to RGB, to 3x416x416
      img = np.ascontiguousarray(img).astype(np.float32)
  
      img /= 255.0  # scale (0, 255) to (0, 1)
      img = np.expand_dims(img, axis=0)  # add batch dimension
  
      # compute ONNX Runtime output prediction
      ort_inputs = {"images": img}
  
      t1 = time.time()
      # prediction: [num_obj, 85]
      pred = ort_session.run(None, ort_inputs)[0]
      t2 = time.time()
      print(t2 - t1)
      # print(predictions.shape[0])
      # process detections
      # 这里预测的数值是相对坐标(0-1之间)，乘上图像尺寸转回绝对坐标
      pred[:, [0, 2]] *= input_size[1]
      pred[:, [1, 3]] *= input_size[0]
      pred = post_process(pred)
  
      # 将预测的bbox缩放回原图像尺度
      p_boxes = turn_back_coords(
          img1_shape=img.shape[2:],
          coords=pred[:, :4],
          img0_shape=img_o.shape,
          ratio_pad=[ratio, pad],
      ).round()
      # print(p_boxes.shape)
  
      bboxes = p_boxes
      scores = pred[:, 4]
      classes = pred[:, 5].astype(np.int) + 1
  
      category_index = dict([(i + 1, str(i + 1)) for i in range(90)])
      img_o = draw_box(
          img_o[:, :, ::-1], bboxes, classes, scores, category_index
      )
      plt.imshow(img_o)
      plt.show()
  
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 9 for calling a global function with example usage: main() without return types