o
    éôj¹-  ã                   @  sü  d dl mZ g d¢Zd dlZd dl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mZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, d d	l-m.Z.m/Z/ d d
l0m1Z1m2Z2m3Z3 d dl4m5Z6 d dlm7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC eed eDf ZEdZFdCdd„ZGdDdd„ZHdEdd„ZI	dFdGd!d"„ZJ		#dHdId(d)„ZK	dFdJd+d,„ZLeFfdKd0d1„ZMeFfdLd2d3„ZN	dFd4d#dd5d4d6œdMd?d@„ZO	dFdNdAdB„ZPeKZQeMZReOZSdS )Oé    )Úannotations)8ÚONNX_MLÚ
IR_VERSIONÚIR_VERSION_2017_10_10ÚIR_VERSION_2017_10_30ÚIR_VERSION_2017_11_3ÚIR_VERSION_2019_1_22ÚIR_VERSION_2019_3_18ÚIR_VERSION_2019_9_19ÚIR_VERSION_2020_5_8ÚIR_VERSION_2021_7_30ÚIR_VERSION_2023_5_5ÚEXPERIMENTALÚSTABLEÚcheckerÚcomposeÚdefsÚ	gen_protoÚhelperÚhubÚmappingÚnumpy_helperÚparserÚprinterÚshape_inferenceÚutilsÚversion_converterÚAttributeProtoÚFunctionProtoÚ
GraphProtoÚMapProtoÚ
ModelProtoÚ	NodeProtoÚOperatorProtoÚOperatorSetIdProtoÚOperatorSetProtoÚOperatorStatusÚOptionalProtoÚSequenceProtoÚSparseTensorProtoÚStringStringEntryProtoÚTensorAnnotationÚTensorProtoÚTensorShapeProtoÚTrainingInfoProtoÚ	TypeProtoÚValueInfoProtoÚVersionÚconvert_model_to_external_dataÚload_external_data_for_modelÚload_model_from_stringÚ
load_modelÚload_tensor_from_stringÚload_tensorÚ
save_modelÚsave_tensorÚwrite_external_data_tensorsN)ÚIOÚLiteralÚUnion)Úserialization)r   )r3   r:   r2   )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/   r0   r1   )r#   r%   )r    r'   r(   )Úversion)r   r   r   r   r   r   r   r   r   r   r   r   r   )ÚprotobufZ	textprotor@   ÚfúIO[bytes] | str | os.PathLikeÚreturnÚbytesc                 C  s†   t | dƒrtt tt | ¡jƒrt tt | ¡ ¡ }|S t ttt	j
f | ¡} t| dƒ�}| ¡ }W d   ƒ |S 1 s<w   Y  |S )NÚreadÚrb)ÚhasattrÚcallableÚtypingÚcastr;   rD   rE   r=   ÚstrÚosÚPathLikeÚopen)rA   ÚcontentÚreadable© rQ   ú`/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/onnx/__init__.pyÚ_load_bytesŽ   s    ý

ÿþrS   rO   ÚNonec                 C  sŠ   t |dƒrtt tt |¡jƒrt tt |¡ | ¡ d S t ttt	j
f |¡}t|dƒ�}| | ¡ W d   ƒ d S 1 s>w   Y  d S )NÚwriteÚwb)rG   rH   rI   rJ   r;   rD   rU   r=   rK   rL   rM   rN   )rO   rA   ÚwritablerQ   rQ   rR   Ú_save_bytes˜   s    "ÿrX   ú$IO[bytes] | str | os.PathLike | Noneú
str | Nonec                 C  sD   t | ttjfƒrtj | ¡S t| dƒr | d usJ ‚tj | j¡S d S )NÚname)Ú
isinstancerK   rL   rM   ÚpathÚabspathrG   r[   )rA   rQ   rQ   rR   Ú_get_file_path¡   s   
r_   Úfmtú_SupportedFormat | Noneú$str | os.PathLike | IO[bytes] | Noneúserialization.ProtoSerializerc                 C  s`   | dur
t j | ¡S t|ƒ }dur tj |¡\}}t j |¡} | p#t} | dus*J ‚t j | ¡S )zQGet the serializer for the given path and format from the serialization registry.N)	r>   ÚregistryÚgetr_   rL   r]   ÚsplitextZget_format_from_file_extensionÚ_DEFAULT_FORMAT)r`   rA   Ú	file_pathÚ_ÚextrQ   rQ   rR   Ú_get_serializerª   s   rk   TÚformatÚload_external_dataÚboolr!   c                 C  sB   t || ƒ t| ƒtƒ ¡}|rt| ƒ}|rtj |¡}t||ƒ |S )a  Loads a serialized ModelProto into memory.

    Args:
        f: can be a file-like object (has "read" function) or a string/PathLike containing a file name
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.
        load_external_data: Whether to load the external data.
            Set to True if the data is under the same directory of the model.
            If not, users need to call :func:`load_external_data_for_model`
            with directory to load external data from.

    Returns:
        Loaded in-memory ModelProto.
    )	rk   Údeserialize_protorS   r!   r_   rL   r]   Údirnamer3   )rA   rl   rm   ÚmodelÚmodel_filepathÚbase_dirrQ   rQ   rR   r5   ½   s   
r5   r,   c                 C  s   t || ƒ t| ƒtƒ ¡S )a  Loads a serialized TensorProto into memory.

    Args:
        f: can be a file-like object (has "read" function) or a string/PathLike containing a file name
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.

    Returns:
        Loaded in-memory TensorProto.
    )rk   ro   rS   r,   )rA   rl   rQ   rQ   rR   r7   Ý   s   r7   Úsúbytes | strÚ_SupportedFormatc                 C  ó   t |ƒ | tƒ ¡S )aì  Loads a binary string (bytes) that contains serialized ModelProto.

    Args:
        s: a string, which contains serialized ModelProto
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.

    Returns:
        Loaded in-memory ModelProto.
    )rk   ro   r!   ©rt   rl   rQ   rQ   rR   r4   ð   ó   r4   c                 C  rw   )aï  Loads a binary string (bytes) that contains serialized TensorProto.

    Args:
        s: a string, which contains serialized TensorProto
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.

    Returns:
        Loaded in-memory TensorProto.
    )rk   ro   r,   rx   rQ   rQ   rR   r6     ry   r6   Fi   )Úsave_as_external_dataÚall_tensors_to_one_fileÚlocationÚsize_thresholdÚconvert_attributeÚprotoúModelProto | bytesrz   r{   r|   r}   Úintr~   c                C  st   t | tƒrttƒ | tƒ ¡} |rt| ||||ƒ t|ƒ}|dur+tj	 
|¡}	t| |	ƒ} t||ƒ | ¡}
t|
|ƒ dS )a}  Saves the ModelProto to the specified path and optionally, serialize tensors with raw data as external data before saving.

    Args:
        proto: should be a in-memory ModelProto
        f: can be a file-like object (has "write" function) or a string containing
        a file name or a pathlike object
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.
        save_as_external_data: If true, save tensors to external file(s).
        all_tensors_to_one_file: Effective only if save_as_external_data is True.
            If true, save all tensors to one external file specified by location.
            If false, save each tensor to a file named with the tensor name.
        location: Effective only if save_as_external_data is true.
            Specify the external file that all tensors to save to.
            Path is relative to the model path.
            If not specified, will use the model name.
        size_threshold: Effective only if save_as_external_data is True.
            Threshold for size of data. Only when tensor's data is >= the size_threshold it will be converted
            to external data. To convert every tensor with raw data to external data set size_threshold=0.
        convert_attribute: Effective only if save_as_external_data is True.
            If true, convert all tensors to external data
            If false, convert only non-attribute tensors to external data
    N)r\   rD   rk   rg   ro   r!   r2   r_   rL   r]   rp   r:   Úserialize_protorX   )r   rA   rl   rz   r{   r|   r}   r~   rr   ÚbasepathÚ
serializedrQ   rQ   rR   r8     s   
$
ÿ
r8   c                 C  s   t ||ƒ | ¡}t||ƒ dS )a  Saves the TensorProto to the specified path.

    Args:
        proto: should be a in-memory TensorProto
        f: can be a file-like object (has "write" function) or a string
        containing a file name or a pathlike object.
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.
    N)rk   r‚   rX   )r   rA   rl   r„   rQ   rQ   rR   r9   K  s   r9   )rA   rB   rC   rD   )rO   rD   rA   rB   rC   rT   )rA   rY   rC   rZ   )N)r`   ra   rA   rb   rC   rc   )NT)rA   rB   rl   ra   rm   rn   rC   r!   )rA   rB   rl   ra   rC   r,   )rt   ru   rl   rv   rC   r!   )rt   rD   rl   rv   rC   r,   )r   r€   rA   rB   rl   ra   rz   rn   r{   rn   r|   rZ   r}   r�   r~   rn   rC   rT   )r   r,   rA   rB   rl   ra   rC   rT   )TÚ
__future__r   Ú__all__rL   rI   r;   r<   r=   Úonnxr>   Zonnx.onnx_cpp2py_exportr   Zonnx.external_data_helperr3   r:   r2   Zonnx.onnx_pbr   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/   r0   r1   Zonnx.onnx_operators_pbr#   r%   Zonnx.onnx_data_pbr    r'   r(   Zonnx.versionr?   Ú__version__r   r   r   r   r   r   r   r   r   r   r   r   r   rK   rv   rg   rS   rX   r_   rk   r5   r7   r4   r6   r8   r9   ÚloadZload_from_stringÚsaverQ   rQ   rQ   rR   Ú<module>   sT   @x<



	
ÿý"þþþý÷8ý