U
    T?h                     @   s@   d Z ddlmZmZ ddlmZ ddlmZ G dd deZdS )z 
Implements ONNX's backend API.
    )AnyTuple)
BackendRep)
RunOptionsc                   @   s    e Zd ZdZdd Zdd ZdS )OnnxRuntimeBackendRepzr
    Computes the prediction for a pipeline converted into
    an :class:`onnxruntime.InferenceSession` node.
    c                 C   s
   || _ dS )zG
        :param session: :class:`onnxruntime.InferenceSession`
        N)_session)selfsession r
   Q/var/www/html/venv/lib/python3.8/site-packages/onnxruntime/backend/backend_rep.py__init__   s    zOnnxRuntimeBackendRep.__init__c           
         s   t  }| D ]\}}t||rt||| qt|tri }t| j D ]\}}|| ||j	< qJ| j
d|| t tr S dd | j D }	 fdd|	D S nH| j }t|dkrtdt| d|d j	|i}| j
d||S dS )	z`
        Computes the prediction.
        See :meth:`onnxruntime.InferenceSession.run`.
        Nc                 S   s   g | ]
}|j qS r
   )name).0or
   r
   r   
<listcomp>.   s     z-OnnxRuntimeBackendRep.run.<locals>.<listcomp>c                    s   g | ]} | qS r
   r
   )r   r   Zoutsr
   r   r   /   s        zModel expect z inputsr   )r   itemshasattrsetattr
isinstancelist	enumerater   
get_inputsr   runget_outputslenRuntimeError)
r   inputskwargsoptionskvZinpsiZinpZoutput_namesr
   r   r   r      s$    



zOnnxRuntimeBackendRep.runN)__name__
__module____qualname____doc__r   r   r
   r
   r
   r   r      s   r   N)	r'   typingr   r   Zonnx.backend.baser   Zonnxruntimer   r   r
   r
   r
   r   <module>   s   