
    FPh                     8    d dl mZ d dlmZ d dlZ G d d      Zy)    )List)urlsplitNc                   d    e Zd ZdZd
dededefdZdej                  deej                     fdZ	y	)TritonRemoteModela  
    Client for interacting with a remote Triton Inference Server model.

    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.
    urlendpointschemec                    |sR|sPt        |      }|j                  j                  d      j                  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	   }|j                  | _        |j                   | _        t"        j$                  t"        j&                  t"        j(                  d
}|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}| _        yc c}w c c}w c c}w c c}w )a  
        Initialize the TritonRemoteModel.

        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): The name of the model on the Triton server.
            scheme (str): The communication scheme ('http' or 'grpc').
        /r   httpNF)r   verbosesslT)as_jsonconfig)	TYPE_FP32	TYPE_FP16
TYPE_UINT8input	data_typenameoutput)r   pathstripsplitr	   netlocr   r   tritonclient.httpr   InferenceServerClienttriton_clientget_model_configtritonclient.grpcgrpcInferRequestedOutput
InferInputnpfloat32float16uint8input_formatsnp_input_formatsinput_namesoutput_names)	selfr   r   r	   splitsclientr   type_mapxs	            cC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\ultralytics/utils/triton.py__init__zTritonRemoteModel.__init__   s    c]F{{((-33C8;H]]F--C  V.!'!=!=$((TY_d!=!eD''88BF.!'!=!=$((TY_d!=!eD''8848PQYZF$*$?$?! ++!#"**TVT\T\]6<WoFoanoF6:6H6H I6H!6H I/5g?!AfI?06x0@A0@1QvY0@A G I?As   F<1GG'Ginputsreturnc           	         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 )z
        Call the model with the given inputs.

        Args:
            *inputs (List[np.ndarray]): Input data to the model.

        Returns:
            List[np.ndarray]: Model outputs.
        r   TYPE_ )
model_namer3   outputs)dtype	enumerater)   astyper#   r*   shaper(   replaceset_data_from_numpyappendr+   r"   r   inferr   as_numpy)
r,   r3   infer_inputsinput_formatir0   infer_inputoutput_nameinfer_outputsr9   s
             r1   __call__zTritonRemoteModel.__call__A   sA    ayf%DAqww$//22HHT22156//$*:*:1*=zz4K]K]^_K`KhKhiprtKuvK++A., & TXSdSdeSdK22;?Sde$$**dmmLbo*pVZVgVghVg{  -44\BVghh f is   E('EN)r7   r7   )
__name__
__module____qualname____doc__strr2   r$   ndarrayr   rI        r1   r   r   	   sI    &BC &B3 &BS &BPi

 itBJJ/? irQ   r   )typingr   urllib.parser   numpyr$   r   rP   rQ   r1   <module>rU      s     ! Ni NirQ   