parameters: (self, engine_path, precision, calib_input=None, calib_cache=None, calib_num_images=5000,
                        calib_batch_size=8)
docstring: Build the TensorRT engine and serialize it to disk.
          :param engine_path: The path where to serialize the engine to.
          :param precision: The datatype to use for the engine, either 'fp32', 'fp16' or 'int8'.
          :param calib_input: The path to a directory holding the calibration images.
          :param calib_cache: The path where to write the calibration cache to, or if it already exists, load it from.
          :param calib_num_images: The maximum number of images to use for calibration.
          :param calib_batch_size: The batch size to use for the calibration process.
docstring_summary: Build the TensorRT engine and serialize it to disk.
          :param engine_path: The path where to serialize the engine to.
          :param precision: The datatype to use for the engine, either 'fp32', 'fp16' or 'int8'.
          :param calib_input: The path to a directory holding the calibration images.
          :param calib_cache: The path where to write the calibration cache to, or if it already exists, load it from.
          :param calib_num_images: The maximum number of images to use for calibration.
          :param calib_batch_size: The batch size to use for the calibration process.
docstring_tokens: Build the TensorRT engine and serialize it to disk . : param engine_path : The path where to serialize the engine to . : param precision : The datatype to use for the engine either fp32 fp16 or int8 . : param calib_input : The path to a directory holding the calibration images . : param calib_cache : The path where to write the calibration cache to or if it already exists load it from . : param calib_num_images : The maximum number of images to use for calibration . : param calib_batch_size : The batch size to use for the calibration process .
function: def create_engine(self, engine_path, precision, calib_input=None, calib_cache=None, calib_num_images=5000,
                        calib_batch_size=8):
          """
          Build the TensorRT engine and serialize it to disk.
          :param engine_path: The path where to serialize the engine to.
          :param precision: The datatype to use for the engine, either 'fp32', 'fp16' or 'int8'.
          :param calib_input: The path to a directory holding the calibration images.
          :param calib_cache: The path where to write the calibration cache to, or if it already exists, load it from.
          :param calib_num_images: The maximum number of images to use for calibration.
          :param calib_batch_size: The batch size to use for the calibration process.
          """
          engine_path = os.path.realpath(engine_path)
          engine_dir = os.path.dirname(engine_path)
          os.makedirs(engine_dir, exist_ok=True)
          log.info("Building {} Engine in {}".format(precision, engine_path))
  
          inputs = [self.network.get_input(i) for i in range(self.network.num_inputs)]
  
          if precision == "fp16":
              if not self.builder.platform_has_fast_fp16:
                  log.warning("FP16 is not supported natively on this platform/device")
              else:
                  self.config.set_flag(trt.BuilderFlag.FP16)
          elif precision == "int8":
              if not self.builder.platform_has_fast_int8:
                  log.warning("INT8 is not supported natively on this platform/device")
              else:
                  if self.builder.platform_has_fast_fp16:
                      # Also enable fp16, as some layers may be even more efficient in fp16 than int8
                      self.config.set_flag(trt.BuilderFlag.FP16)
                  self.config.set_flag(trt.BuilderFlag.INT8)
                  self.config.int8_calibrator = EngineCalibrator(calib_cache)
                  if not os.path.exists(calib_cache):
                      calib_shape = [calib_batch_size] + list(inputs[0].shape[1:])
                      calib_dtype = trt.nptype(inputs[0].dtype)
                      self.config.int8_calibrator.set_image_batcher(
                          ImageBatcher(calib_input, calib_shape, calib_dtype, max_num_images=calib_num_images,
                                       exact_batches=True))
  
          with self.builder.build_engine(self.network, self.config) as engine, open(engine_path, "wb") as f:
              log.info("Serializing engine to file: {:}".format(engine_path))
              f.write(engine.serialize())
function_tokens: def create_engine ( self , engine_path , precision , calib_input = None , calib_cache = None , calib_num_images = 5000 , calib_batch_size = 8 ) : engine_path = os . path . realpath ( engine_path ) engine_dir = os . path . dirname ( engine_path ) os . makedirs ( engine_dir , exist_ok = True ) log . info ( "Building {} Engine in {}" . format ( precision , engine_path ) ) inputs = [ self . network . get_input ( i ) for i in range ( self . network . num_inputs ) ] if precision == "fp16" : if not self . builder . platform_has_fast_fp16 : log . warning ( "FP16 is not supported natively on this platform/device" ) else : self . config . set_flag ( trt . BuilderFlag . FP16 ) elif precision == "int8" : if not self . builder . platform_has_fast_int8 : log . warning ( "INT8 is not supported natively on this platform/device" ) else : if self . builder . platform_has_fast_fp16 : # Also enable fp16, as some layers may be even more efficient in fp16 than int8 self . config . set_flag ( trt . BuilderFlag . FP16 ) self . config . set_flag ( trt . BuilderFlag . INT8 ) self . config . int8_calibrator = EngineCalibrator ( calib_cache ) if not os . path . exists ( calib_cache ) : calib_shape = [ calib_batch_size ] + list ( inputs [ 0 ] . shape [ 1 : ] ) calib_dtype = trt . nptype ( inputs [ 0 ] . dtype ) self . config . int8_calibrator . set_image_batcher ( ImageBatcher ( calib_input , calib_shape , calib_dtype , max_num_images = calib_num_images , exact_batches = True ) ) with self . builder . build_engine ( self . network , self . config ) as engine , open ( engine_path , "wb" ) as f : log . info ( "Serializing engine to file: {:}" . format ( engine_path ) ) f . write ( engine . serialize ( ) )