Ë
    Fêñi_  ã                  ó@   — d dl mZ d dlZd dlmZ d dlZ G d„ d«      Zy)é    )ÚannotationsN)Úurlsplitc                  ó"   — e Zd ZdZddd„Zdd„Zy)ÚTritonRemoteModela  Client for interacting with a remote Triton Inference Server model.

    This class provides a convenient interface for sending inference requests to a Triton Inference Server and
    processing the responses. Supports both HTTP and gRPC communication protocols.

    Attributes:
        endpoint (str): The name of the model on the Triton server.
        url (str): The URL of the Triton server.
        triton_client: The Triton client (either HTTP or gRPC).
        InferInput: The input class for the Triton client.
        InferRequestedOutput: The output request class for the Triton client.
        input_formats (list[str]): The data types of the model inputs.
        np_input_formats (list[type]): The numpy data types of the model inputs.
        input_names (list[str]): The names of the model inputs.
        output_names (list[str]): The names of the model outputs.
        metadata: The metadata associated with the model.

    Methods:
        __call__: Call the model with the given inputs and return the outputs.

    Examples:
        Initialize a Triton client with HTTP
        >>> model = TritonRemoteModel(url="localhost:8000", endpoint="yolov8", scheme="http")

        Make inference with numpy arrays
        >>> outputs = model(np.random.rand(1, 3, 640, 640).astype(np.float32))
    c                ó^  — |sS|sQt        |«      }|j                  j                  d«      j                  dd«      d   }|j                  }|j
                  }|| _        || _        |dk(  rEddlm	} |j                  | j                  dd¬«      | _        | j                  j                  |«      }nIddlm} |j                  | j                  dd¬«      | _        | j                  j                  |d¬	«      d
   }t        |d   d„ ¬«      |d<   t         j"                  t         j$                  t         j&                  dœ}|j(                  | _        |j*                  | _        |d   D �cg c]  }|d   ‘Œ	 c}| _        | j,                  D �cg c]  }||   ‘Œ	 c}| _        |d   D �cg c]  }|d   ‘Œ	 c}| _        |d   D �cg c]  }|d   ‘Œ	 c}| _        t5        j6                  |j9                  di «      j9                  di «      j9                  dd«      «      | _        yc c}w c c}w c c}w c c}w )aá  Initialize the TritonRemoteModel for interacting with a remote Triton Inference Server.

        Arguments may be provided individually or parsed from a collective 'url' argument of the form
        <scheme>://<netloc>/<endpoint>/<task_name>

        Args:
            url (str): The URL of the Triton server.
            endpoint (str, optional): The name of the model on the Triton server.
            scheme (str, optional): The communication scheme ('http' or 'grpc').
        ú/é   r   ÚhttpNF)ÚurlÚverboseÚsslT)Úas_jsonÚconfigÚoutputc                ó$   — | j                  d«      S )NÚname)Úget)Úxs    úZ/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/utils/triton.pyú<lambda>z,TritonRemoteModel.__init__.<locals>.<lambda>I   s   € À!Ç%Á%ÈÃ-€ ó    )Úkey)Ú	TYPE_FP32Ú	TYPE_FP16Ú
TYPE_UINT8ÚinputÚ	data_typer   Ú
parametersÚmetadataÚstring_valueÚNone)r   ÚpathÚstripÚsplitÚschemeÚnetlocÚendpointr   Útritonclient.httpr
   ÚInferenceServerClientÚtriton_clientÚget_model_configÚtritonclient.grpcÚgrpcÚsortedÚnpÚfloat32Úfloat16Úuint8ÚInferRequestedOutputÚ
InferInputÚinput_formatsÚnp_input_formatsÚinput_namesÚoutput_namesÚastÚliteral_evalr   r   )	Úselfr   r'   r%   ÚsplitsÚclientr   Útype_mapr   s	            r   Ú__init__zTritonRemoteModel.__init__(   sè  € ñ ¡Ü˜c“]ˆFØ—{‘{×(Ñ(¨Ó-×3Ñ3°C¸Ó;¸AÑ>ˆHØ—]‘]ˆFØ—-‘-ˆCà ˆŒØˆŒð �VÒÝ.à!'×!=Ñ!=À$Ç(Á(ÐTYÐ_dÐ!=Ó!eˆDÔØ×'Ñ'×8Ñ8¸ÓB‰Få.à!'×!=Ñ!=À$Ç(Á(ÐTYÐ_dÐ!=Ó!eˆDÔØ×'Ñ'×8Ñ8¸È4Ð8ÓPÐQYÑZˆFô " &¨Ñ"2Ñ8OÔPˆˆxÑô "$§¡¼"¿*¹*ÔTV×T\ÑT\Ñ]ˆØ$*×$?Ñ$?ˆÔ!Ø ×+Ñ+ˆŒØ6<¸W±oÖF°˜a ›nÒFˆÔØ6:×6HÑ6HÖ I° ¨!£Ò IˆÔØ/5°g©Ö?¨!˜A˜f›IÒ?ˆÔØ06°xÑ0@ÖA¨1˜Q˜v›YÒAˆÔÜ×(Ñ(¨¯©°LÀ"Ó)E×)IÑ)IÈ*ÐVXÓ)Y×)]Ñ)]Ð^lÐntÓ)uÓvˆ�ùò	 GùÚ IùÚ?ùÚAs   Å$HÆH Æ!H%Æ<H*c           	     ó¸  — g }|d   j                   }t        |«      D ]ª  \  }}|j                   | j                  |   k7  r|j                  | j                  |   «      }| j	                  | j
                  |   g |j                  ¢| j                  |   j                  dd«      «      }|j                  |«       |j                  |«       Œ¬ | j                  D �cg c]  }| j                  |«      ‘Œ }}| j                  j                  | j                  ||¬«      }	| j                  D �cg c]"  }|	j!                  |«      j                  |«      ‘Œ$ c}S c c}w c c}w )a…  Call the model with the given inputs and return inference results.

        Args:
            *inputs (np.ndarray): Input data to the model. Each array should match the expected shape and type for the
                corresponding model input.

        Returns:
            (list[np.ndarray]): Model outputs cast to the dtype of the first input. Each element in the list corresponds
                to one of the model's output tensors.

        Examples:
            >>> model = TritonRemoteModel(url="localhost:8000", endpoint="yolov8", scheme="http")
            >>> outputs = model(np.random.rand(1, 3, 640, 640).astype(np.float32))
        r   ÚTYPE_Ú )Ú
model_nameÚinputsÚoutputs)ÚdtypeÚ	enumerater6   Úastyper4   r7   Úshaper5   ÚreplaceÚset_data_from_numpyÚappendr8   r3   r*   Úinferr'   Úas_numpy)
r;   rD   Úinfer_inputsÚinput_formatÚir   Úinfer_inputÚoutput_nameÚinfer_outputsrE   s
             r   Ú__call__zTritonRemoteModel.__call__U   s=  € ð ˆØ˜a‘y—‘ˆÜ˜fÓ%ò 	-‰DˆAˆqØ�w‰w˜$×/Ñ/°Ñ2Ò2Ø—H‘H˜T×2Ñ2°1Ñ5Ó6�ØŸ/™/¨$×*:Ñ*:¸1Ñ*=¸zÀÇÁ¸zÈ4×K]ÑK]Ð^_ÑK`×KhÑKhÐipÐrtÓKuÓvˆKØ×+Ñ+¨AÔ.Ø×Ñ Õ,ð	-ð TX×SdÑSdÖeÀK˜×2Ñ2°;Õ?ÐeˆÐeØ×$Ñ$×*Ñ*°d·m±mÈLÐboÐ*ÓpˆàVZ×VgÑVgÖhÀ{�× Ñ  Ó-×4Ñ4°\ÕBÒhÐhùò fùò is   ÃEÄ('EN)rB   rB   )r   Ústrr'   rV   r%   rV   )rD   z
np.ndarrayÚreturnzlist[np.ndarray])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r?   rU   © r   r   r   r      s   „ ñô8+wôZir   r   )Ú
__future__r   r9   Úurllib.parser   Únumpyr/   r   r\   r   r   ú<module>r`      s!   ðõ #ã 
Ý !ã ÷eiò eir   