example/tensorrt/resnet50/trt_profiler.py
def do_inference(engine, pics_1, h_input_1, d_input_1, h_output, d_output, stream, batch_size):
   """
   This is the function to run the inference
   Args:
      engine      : Path to the TensorRT engine 
      pics_1      : Input images to the model.  
      h_input_1   : Input in the host         
      d_input_1   : Input in the device 
      h_output_1  : Output in the host 
      d_output_1  : Output in the device 
      stream      : CUDA stream
      batch_size  : Batch size for execution time
   
   Output:
      The list of output images

   """

   load_images_to_buffer(pics_1, h_input_1)

   with engine.create_execution_context() as context:

      """ copy data from host to device """
      cuda.memcpy_htod_async(d_input_1, h_input_1, stream)

      # Run inference.
      context.profiler = trt.Profiler()
      context.execute(batch_size=1, bindings=[int(d_input_1), int(d_output)])

      # Transfer predictions back from the GPU.
      cuda.memcpy_dtoh_async(h_output, d_output, stream)

      # Synchronize the stream
      stream.synchronize()

      # Return the host output.
      return h_output

   This is the function to run the inference
   Args:
      engine      : Path to the TensorRT engine 
      pics_1      : Input images to the model.  
      h_input_1   : Input in the host         
      d_input_1   : Input in the device 
      h_output_1  : Output in the host 
      d_output_1  : Output in the device 
      stream      : CUDA stream
      batch_size  : Batch size for execution time
   
   Output:
      The list of output images

   
This is the function to run the inference
This is the function to run the inference
def do_inference(engine, pics_1, h_input_1, d_input_1, h_output, d_output, stream, batch_size):
   load_images_to_buffer(pics_1, h_input_1)
   with engine.create_execution_context() as context:
      cuda.memcpy_htod_async(d_input_1, h_input_1, stream)
      context.profiler = trt.Profiler()
      context.execute(batch_size=1, bindings=[int(d_input_1), int(d_output)])
      cuda.memcpy_dtoh_async(h_output, d_output, stream)
      stream.synchronize()
      return h_output
def do_inference ( engine , pics_1 , h_input_1 , d_input_1 , h_output , d_output , stream , batch_size ) : load_images_to_buffer ( pics_1 , h_input_1 ) with engine . create_execution_context ( ) as context : """ copy data from host to device """ cuda . memcpy_htod_async ( d_input_1 , h_input_1 , stream ) context . profiler = trt . Profiler ( ) context . execute ( batch_size = 1 , bindings = [ int ( d_input_1 ) , int ( d_output ) ] ) cuda . memcpy_dtoh_async ( h_output , d_output , stream ) stream . synchronize ( ) return h_output
This is the function to run the inference
This is the function to run the inference
"""
   This is the function to run the inference
   Args:
      engine      : Path to the TensorRT engine 
      pics_1      : Input images to the model.  
      h_input_1   : Input in the host         
      d_input_1   : Input in the device 
      h_output_1  : Output in the host 
      d_output_1  : Output in the device 
      stream      : CUDA stream
      batch_size  : Batch size for execution time
   
   Output:
      The list of output images

   """ """ copy data from host to device """ # Run inference. # Transfer predictions back from the GPU. # Synchronize the stream # Return the host output.
engine
pics_1
h_input_1
d_input_1
h_output
d_output
stream
batch_size
engine      
Path to the TensorRT engine
Path to the TensorRT engine
pics_1      
Input images to the model.
Input images to the model .
h_input_1   
Input in the host
Input in the host
d_input_1   
Input in the device
Input in the device
h_output_1  
Output in the host
Output in the host
d_output_1  
Output in the device
Output in the device
stream      
None
batch_size  
Batch size for execution time
Batch size for execution time