parameters: (self, inputs=None)
docstring: Builds a TensorRT engine with a builder config.
          :param inputs: inputs to the model; if not None, this means we are building the engine at run time,
                         because we need to register optimization profiles for some inputs
          :type inputs: List of np.ndarray
docstring_summary: Builds a TensorRT engine with a builder config.
          :param inputs: inputs to the model; if not None, this means we are building the engine at run time,
                         because we need to register optimization profiles for some inputs
          :type inputs: List of np.ndarray
docstring_tokens: Builds a TensorRT engine with a builder config . : param inputs : inputs to the model ; if not None this means we are building the engine at run time because we need to register optimization profiles for some inputs : type inputs : List of np . ndarray
function: def _build_engine(self, inputs=None):
          """
          Builds a TensorRT engine with a builder config.
          :param inputs: inputs to the model; if not None, this means we are building the engine at run time,
                         because we need to register optimization profiles for some inputs
          :type inputs: List of np.ndarray
          """
  
          if inputs:
              opt_profile = self.builder.create_optimization_profile()
              # Set optimization profiles for the input bindings that need them
              for i in range(self.network.num_inputs):
                  inp_tensor = self.network.get_input(i)
                  name = inp_tensor.name
                  # Set profiles for shape tensors
                  if inp_tensor.is_shape_tensor:
                      if inputs[i].ndim > 0:
                          val_list = inputs[i].tolist()
                          opt_profile.set_shape_input(name, val_list, val_list, val_list)
                      else:
                          opt_profile.set_shape_input(name, [inputs[i]], [inputs[i]], [inputs[i]])
                  # Set profiles for dynamic execution tensors
                  elif -1 in inp_tensor.shape:
                      opt_profile.set_shape(name, inputs[i].shape, inputs[i].shape, inputs[i].shape)
  
              self.config.add_optimization_profile(opt_profile)
  
          trt_engine = self.builder.build_engine(self.network, self.config)
  
          if trt_engine is None:
              raise RuntimeError("Failed to build TensorRT engine from network")
          if self.serialize_engine:
              trt_engine = self._serialize_deserialize(trt_engine)
          self.engine = Engine(trt_engine)
function_tokens: def _build_engine ( self , inputs = None ) : if inputs : opt_profile = self . builder . create_optimization_profile ( ) # Set optimization profiles for the input bindings that need them for i in range ( self . network . num_inputs ) : inp_tensor = self . network . get_input ( i ) name = inp_tensor . name # Set profiles for shape tensors if inp_tensor . is_shape_tensor : if inputs [ i ] . ndim > 0 : val_list = inputs [ i ] . tolist ( ) opt_profile . set_shape_input ( name , val_list , val_list , val_list ) else : opt_profile . set_shape_input ( name , [ inputs [ i ] ] , [ inputs [ i ] ] , [ inputs [ i ] ] ) # Set profiles for dynamic execution tensors elif - 1 in inp_tensor . shape : opt_profile . set_shape ( name , inputs [ i ] . shape , inputs [ i ] . shape , inputs [ i ] . shape ) self . config . add_optimization_profile ( opt_profile ) trt_engine = self . builder . build_engine ( self . network , self . config ) if trt_engine is None : raise RuntimeError ( "Failed to build TensorRT engine from network" ) if self . serialize_engine : trt_engine = self . _serialize_deserialize ( trt_engine ) self . engine = Engine ( trt_engine )