o
    oi#                     @  sd   d dl mZ d dlmZmZmZ d dlmZ d dlmZ	 d dl
mZmZ dgZG dd deeZdS )	    )annotations)AnyOptionalUnion)onnx)onnxruntime)	ONNXMixinONNXRuntimeMixinONNXSequentialc                      s   e Zd ZdZddddddddd.ddZdddd/ fddZd0d1 fddZ	d2d3 fd#d$Zd4 fd)d*Zd0d5 fd,d-Z	  Z
S )6r
   a  ONNXSequential to chain multiple ONNX operators together.

    Args:
        *args: A variable number of ONNX models (either ONNX ModelProto objects or file paths).
            For Hugging Face-hosted models, use the format 'hf://model_name'. Valid `model_name` can be found on
            https://huggingface.co/kornia/ONNX_models. Or a URL to the ONNX model.
        providers: A list of execution providers for ONNXRuntime
            (e.g., ['CUDAExecutionProvider', 'CPUExecutionProvider']).
        session_options: Optional ONNXRuntime session options for optimizing the session.
        io_maps: An optional list of list of tuples specifying input-output mappings for combining models.
            If None, we assume the default input name and output name are "input" and "output" accordingly, and
            only one input and output node for each graph.
            If not None, `io_maps[0]` shall represent the `io_map` for combining the first and second ONNX models.
        cache_dir: The directory where ONNX models are cached locally (only for downloading from HuggingFace).
            Defaults to None, which will use a default `kornia.config.hub_onnx_dir` directory.
        auto_ir_version_conversion: If True, automatically convert the model's IR version to 9, and OPSET version to 17.
            Other versions may be pointed to by `target_ir_version` and `target_opset_version`.
        target_ir_version: The target IR version to convert to.
        target_opset_version: The target OPSET version to convert to.

    NF)	providerssession_optionsio_maps	cache_dirauto_ir_version_conversiontarget_ir_versiontarget_opset_versionargsUnion[onnx.ModelProto, str]r   Optional[list[str]]r   Optional[ort.SessionOptions]r   Optional[list[tuple[str, str]]]r   Optional[str]r   boolr   Optional[int]r   returnNonec          
      G  sX   | j |d|i| _|r| j| j||d| _| j|d| _| j||d}	| j|	d d S )Nr   r   r   )r   )r   r   )session)	_load_ops	operators_auto_version_conversioncombine_combined_opcreate_sessionset_session)
selfr   r   r   r   r   r   r   r   r    r&   J/home/ubuntu/.local/lib/python3.10/site-packages/kornia/onnx/sequential.py__init__4   s   
zONNXSequential.__init__r   list[onnx.ModelProto]c                  sF   |du rd}|du rd}g }|D ]}t  j|||d}|| q|S )a  Automatic conversion of the model's IR/OPSET version to the given target version.

        If `target_ir_version` is not provided, the model is converted to 9 by default.
        If `target_opset_version` is not provided, the model is converted to 17 by default.

        Args:
            args: List of operations to convert.
            target_ir_version: The target IR version to convert to.
            target_opset_version: The target OPSET version to convert to.

        N	      r   )super_onnx_version_conversionappend)r%   r   r   r   op_listop	__class__r&   r'   r    H   s   z'ONNXSequential._auto_version_conversionlist[tuple[str, str]] | Noneonnx.ModelProtoc                   s   t  j| jd|iS )Nr   )r,   _combiner   )r%   r   r1   r&   r'   r!   g   s   zONNXSequential.combinelist[str] | None
Any | Noneort.InferenceSessionc                   s   t  | j||S N)r,   _create_sessionr"   )r%   r   r   r1   r&   r'   r#   j   s   zONNXSequential.create_session	file_pathstrkwargsr   c                   s   t  j| j|fi |S r9   )r,   _exportr"   )r%   r;   r=   r1   r&   r'   exporto   s   zONNXSequential.exportadditional_metadatac                   s   t  | j|S r9   )r,   _add_metadatar"   )r%   r@   r1   r&   r'   add_metadatar   s   zONNXSequential.add_metadata)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r)   r   r   r   r   r   r)   r9   )r   r3   r   r4   )NN)r   r6   r   r7   r   r8   )r;   r<   r=   r   r   r   )r@   r   r   r4   )__name__
__module____qualname____doc__r(   r    r!   r#   r?   rB   __classcell__r&   r&   r1   r'   r
      s$    N)
__future__r   typingr   r   r   kornia.core.externalr   r   ortkornia.core.mixinr   r	   __all__r
   r&   r&   r&   r'   <module>   s   