class_docstr: Model optimized using TensorRT.
  
  The class cannot be directly instantiated, but implements all the core
  methods needed for using TensorRT at inference time.
  
  Attributes:
      network_parameters (ModelParams): The model parameters as batch
              size, input and output sizes.
      engine (any): The tensorRT engine.
      input_names (List[str]): Names associated to the model input tensors.
      output_names (List[str]): Names associated to the model output tensors.
      cuda_stream (any, optional): Stream used for communication with Nvidia
          GPUs.
      nvidia_logger (any, optional): Logger used by the Nvidia service
class_docstr_tok: ["Model","optimized","using","TensorRT",".","The","class","can","not","be","directly","instantiated",",","but","implements","all","the","core","methods","needed","for","using","TensorRT","at","inference","time",".","Attributes",":","network_parameters","(","ModelParams",")",":","The","model","parameters","as","batch","size",",","input","and","output","sizes",".","engine","(","any",")",":","The","tensorRT","engine",".","input_names","(","List","[","str","]",")",":","Names","associated","to","the","model","input","tensors",".","output_names","(","List","[","str","]",")",":","Names","associated","to","the","model","output","tensors",".","cuda_stream","(","any",",","optional",")",":","Stream","used","for","communication","with","Nvidia","GPUs",".","nvidia_logger","(","any",",","optional",")",":","Logger","used","by","the","Nvidia","service"]
code: def _predict_tensors(
      self,
      input_ptrs: Generator[Any, None, None],
      output_ptrs: Generator[Any, None, None],
      input_shapes: Generator[Any, None, None] = None,
  ):
      buffers = [None] * (
          len(self.input_names) + len(self.output_names)
      )
      input_idxs = (
          self.engine[input_name] for input_name in self.input_names
      )
      output_idxs = (
          self.engine[output_name] for output_name in self.output_names
      )
      input_shapes = input_shapes or [None] * len(self.input_names)
      for input_idx, input_ptr, input_shape in zip(
          input_idxs, input_ptrs, input_shapes
      ):
          buffers[input_idx] = input_ptr
          if input_shape is not None:
              # If the input shape is empty, we set it to (1,) because
              # TensorRT doesn't accept empty shapes.
              if input_shape == torch.Size([]):
                  input_shape = torch.Size((1,))
              self.context.set_binding_shape(input_idx, input_shape)
      for output_idx, output_ptr in zip(output_idxs, output_ptrs):
          buffers[output_idx] = output_ptr
      self.context.execute_async_v2(buffers, self.stream_ptr)
      self._synchronize_stream()
  
imports: import json
  import os
  from abc import ABC
  from pathlib import Path
  from tempfile import TemporaryDirectory
  from typing import Any, Union, Dict, Type, List, Tuple, Generator, Optional
  import numpy
  from loguru import logger
  from nebullvm.config import NVIDIA_FILENAMES
  from nebullvm.core.models import Device, DeviceType, ModelParams, DeepLearningFramework
  from nebullvm.operations.inference_learners.base import BaseInferenceLearner, LearnerMetadata, PytorchBaseInferenceLearner, TensorflowBaseInferenceLearner, NumpyBaseInferenceLearner
  from nebullvm.optional_modules.tensorflow import tensorflow
  from nebullvm.optional_modules.tensor_rt import tensorrt, polygraphy
  from nebullvm.optional_modules.torch import torch, ScriptModule
  from nebullvm.tools.data import DataManager
  from nebullvm.tools.transformations import MultiStageTransformation, VerifyContiguity
label_desc: Use image node_id 9 for calling the ONNXTensorRTInferenceLearner obj's underlying member method code with example usage: obj._predict_tensors(input_ptrs, output_ptrs, input_shapes) without return types