code: def build_engine_with_calib(onnx_model_file, calib, input_shape):
      """
      Parameters
      ----------
      """
      builder = trt.Builder(TRT_LOGGER)
      network = builder.create_network(common.explicit_batch())
      trt_config = builder.create_builder_config()
      parser = trt.OnnxParser(network, TRT_LOGGER)
  
      builder.max_batch_size = input_shape[0]
      trt_config.max_workspace_size = common.GiB(8)
      trt_config.set_flag(trt.BuilderFlag.INT8)
      trt_config.set_flag(trt.BuilderFlag.FP16)
      trt_config.set_flag(trt.BuilderFlag.PREFER_PRECISION_CONSTRAINTS)
      trt_config.int8_calibrator = calib
  
      with open(onnx_model_file, "rb") as model:
          if not parser.parse(model.read()):
              for error in range(parser.num_errors):
                  TRT_LOGGER.log(
                      TRT_LOGGER.ERROR, parser.get_error(error)
                  )
              raise ValueError("Failed to parse the ONNX file.")
  
      TRT_LOGGER.log(
          TRT_LOGGER.INFO, f"input number: {network.num_inputs}"
      )
      TRT_LOGGER.log(
          TRT_LOGGER.INFO, f"output number: {network.num_outputs}"
      )
  
      profile = builder.create_optimization_profile()
      input_name = network.get_input(0).name
      profile.set_shape(
          input_name, min=input_shape, opt=input_shape, max=input_shape
      )
      trt_config.add_optimization_profile(profile)
  
      config_network_to_int8(
          network
      )  # not sure whether it is necessary because trt.BuilderFlag.INT8 is set.
  
      engine = builder.build_engine(network, trt_config)
      return engine
  
imports: import time
  import logging
  import tensorrt
  import numpy
  import torch
  from .None import frontend_to_onnx
  from .None import trt_pycuda
  from .backend import BaseModelSpeedup
label_desc: Use image node_id 9 for calling a global function with example usage: build_engine_with_calib(onnx_model_file, calib, input_shape) and returns: engine