code: def predict_image(
      infer_config, engine, img_list, save_coco=False, repeats=1
  ):
      # load preprocess transforms
      transforms = Compose(infer_config.preprocess_infos)
  
      stream = cuda.Stream()
      coco_results = []
      num_data = len(img_list)
      avg_time = []
      with engine.create_execution_context() as context:
          # Allocate host and device buffers
          bindings = create_trt_bindings(engine, context)
          # warmup
          run_trt_context(context, bindings, stream, repeats=10)
          # predict image
          for i, img_path in enumerate(img_list):
              inputs = transforms(img_path)
              inputs_name = [
                  k for k, v in bindings.items() if v["is_input"]
              ]
              inputs = {
                  k: inputs[k][None,]
                  for k in inputs.keys()
                  if k in inputs_name
              }
              # run infer
              for k, v in inputs.items():
                  bindings[k]["cpu_data"][...] = v
              output = run_trt_context(
                  context, bindings, stream, repeats=repeats
              )
              print(
                  f"{i + 1}/{num_data} infer time: {output['infer_time']} ms."
              )
              avg_time.append(output["infer_time"])
              # get output
              for k, v in output.items():
                  if k in bindings.keys():
                      output[k] = np.reshape(v, bindings[k]["shape"])
              if save_coco:
                  coco_results.extend(
                      format_coco_results(
                          os.path.split(img_path)[-1], output
                      )
                  )
      avg_time = np.mean(avg_time)
      print(
          f"Run on {num_data} data, repeats {repeats} times, avg time: {avg_time} ms."
      )
      if save_coco:
          with open(FLAGS.coco_file, "w") as f:
              json.dump(coco_results, f)
          print(f"save coco json to {FLAGS.coco_file}")
  
imports: import time
  import numpy
  import pycuda.autoinit
  import pycuda.driver
  import tensorrt
  from collections import OrderedDict
  import os
  import yaml
  import json
  import glob
  import argparse
  from preprocess import Compose
  from preprocess import coco_clsid2catid
label_desc: Use image node_id 3 for calling a global function with example usage: predict_image(infer_config, engine, img_list, save_coco, repeats) without return types