
    Si[;                    *   S SK Jr  / SQrS SKrS SKrS SKJrJr  S SKJr  S SK	J
r
  S SKJrJrJr  S SKJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2  S S	K3J4r4J5r5  S S
K6J7r7J8r8J9r9  S SK:rS SKJ;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErE  \R                  (       a  S SKGJHrH  \R                  R                  rJ\S   \K-  rLSrMS!S jrNS"S jrOS#S jrP S$     S%S jjrQ  S&       S'S jjrR S$     S(S jjrS\M4     S)S jjrT\M4     S*S jjrU S$SSSSSS.                 S+S jjjrV S$       S,S jjrW\RrX\TrY\VrZS-S jr[S.S jr\S/S jr]S0S  jr^\[\!l_        \\\l_        \]\l_        g)1    )annotations)=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IR_VERSION_2024_3_25EXPERIMENTALSTABLEcheckercomposedefs	gen_protohelpernumpy_helperparserprintershape_inferenceutilsversion_converterAttributeProtoDeviceConfigurationProtoFunctionProto
GraphProtoIntIntListEntryProtoMapProto
ModelProtoNodeDeviceConfigurationProto	NodeProtoOperatorProtoOperatorSetIdProtoOperatorSetProtoOperatorStatusOptionalProtoSequenceProtoSimpleShardedDimProtoShardedDimProtoShardingSpecProto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)serialization)r   )r9   r@   r8   )#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.   r/   r0   r1   r2   r3   r4   r5   r6   r7   )r&   r(   )r"   r*   r+   )r   r   r   r   r   r   r   r   r   r   r   )Sequence)protobuf	textprotoonnxtxtjsonrE   c                p   [        U S5      (       aV  [        [        R                  " SU 5      R                  5      (       a'  [        R                  " SU 5      R	                  5       nU$ [        R                  " SU 5      n [        U S5       nUR	                  5       nS S S 5        U$ ! , (       d  f       W$ = f)Nread	IO[bytes]str | os.PathLikerb)hasattrcallabletypingcastrJ   open)fcontentreadables      L/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx/__init__.py_load_bytesrW      s    q&hv{{;'B'G'GHH++k1-224
 N KK+Q/!T]hmmoG N ]Ns   B&&
B5c                n   [        US5      (       aV  [        [        R                  " SU5      R                  5      (       a'  [        R                  " SU5      R	                  U 5        g [        R                  " SU5      n[        US5       nUR	                  U 5        S S S 5        g ! , (       d  f       g = f)NwriterK   rL   wb)rN   rO   rP   rQ   rY   rR   )rT   rS   writables      rV   _save_bytesr\      su    q'xK(C(I(IJJK#))'2KK+Q/!T]hNN7# ]]s   B&&
B4c                
   [        U [        [        R                  45      (       a  [        R                  R                  U 5      $ [        U S5      (       a.  U c   e[        R                  R                  U R                  5      $ g )Nname)
isinstancestrosPathLikepathabspathrN   r^   )rS   s    rV   _get_file_pathre      s\    !c2;;'((wwq!!q&}}wwqvv&&    c                H   U b  [         R                  R                  U 5      $ [        U5      =nb@  [        R
                  R                  U5      u  p4[         R                  R                  U5      n U =(       d    [        n U c   e[         R                  R                  U 5      $ )zQGet the serializer for the given path and format from the serialization registry.)	rC   registrygetre   ra   rc   splitextget_format_from_file_extension_DEFAULT_FORMAT)fmtrS   	file_path_exts        rV   _get_serializerrq      s    
 %%))#..#A&&	3!!),$$CCCH 
 C??!!%%c**rf   Tc                    [        X5      R                  [        U 5      [        5       5      nU(       a<  [	        U 5      nU(       a*  [
        R                  R                  U5      n[        X55        U$ )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.
)	rq   deserialize_protorW   r#   re   ra   rc   dirnamer9   )rS   formatload_external_datamodelmodel_filepathbase_dirs         rV   r;   r;      sP    * F&88QVE'*ww~6H(9Lrf   c                Z    [        X5      R                  [        U 5      [        5       5      $ )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.
)rq   rs   rW   r2   )rS   ru   s     rV   r=   r=      s"      6%77AVVrf   c                H    [        U5      R                  U [        5       5      $ )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.
)rq   rs   r#   sru   s     rV   r:   r:      s      6"44Q
EErf   c                H    [        U5      R                  U [        5       5      $ )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.
)rq   rs   r2   r|   s     rV   r<   r<     s      6"44QFFrf   Fi   )save_as_external_dataall_tensors_to_one_filelocationsize_thresholdconvert_attributec               ^   [        U [        5      (       a'  [        [        5      R	                  U [        5       5      n U(       a  [        XXVU5        [        U5      nUb*  [        R                  R                  U5      n	[        X	5      n [        X(5      R                  U 5      n
[        X5        g)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_   bytesrq   rl   rs   r#   r8   re   ra   rc   rt   r@   serialize_protor\   )protorS   ru   r   r   r   r   r   rx   basepath
serializeds              rV   r>   r>   %  s    H %0BB5*,W&HFW	
 $A&N!77??>2+E< 8HHOJ
rf   c                N    [        X!5      R                  U 5      n[        X15        g)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)rq   r   r\   )r   rS   ru   r   s       rV   r?   r?   Z  s!      !+;;EBJ
rf   c           	        U R                   (       a  SU R                    S3nOSnU R                  (       a  SU R                   S3nOSnU R                  (       a  SU R                   S3nOSnU R                  (       a  SU R                  < 3nOSnU R                  (       a  S[        U R                  5       S3nOSnU R                  (       a  S	[        U R                  5       3nOSnS
U R                   U U U U U U S3	$ )N
, domain='' z, producer_name='z, producer_version='z, graph=z, functions=<z functions>, opset_import=zModelProto(ir_version=))	domainproducer_nameproducer_versiongraph	functionslenopset_import_operator_set_protos_repr
ir_version)selfr   r   r   r   r   r   s          rV   _model_proto_reprr   t  s   {{dkk]!,+D,>,>+?qA1$2G2G1HJzz4::.)~~#C$7#8D		()B4CTCT)U(VW#DOO#4\N6(=/ZjYklqkrs|r}}~rf   c           	        U R                   (       a  S[        U R                   5       S3nOSnU R                  (       a  S[        U R                  5       S3nOSnU R                  (       a  S[        U R                  5       S3nOSnU R                  (       a  S[        U R                  5       S	3nOSnU R
                  (       a  S
[        U R
                  5       S3nOSnSU R                   SU U U U U S3	$ )Nz, initializer=<z initializers>r   , node=< nodes>z, value_info=<z value_info>	, input=< inputs>
, output=<	 outputs>zGraphProto('r   r   )initializerr   node
value_infoinputoutputr^   )r   r   r   r   r   r   s         rV   _graph_proto_reprr     s    'D,<,<(='>nMyy#dii.)1%c$//&:%;<H

zzC

O,H5{{c$++./y9$))AeWVH[M$
|STUUrf   c                |   U R                   (       a  SU R                    S3nOSnU R                  (       a  SU R                   S3nOSnU R                  (       a  S[        U R                  5       S3nOSnU R                  (       a  SU R                   3nOSnU R
                  (       a  S[        U R
                  5       3nOSnU R                  (       a  S	[        U R                  5       S
3nOSnU R                  (       a  S[        U R                  5       S3nOSnSU R                   SU U U U U U U S3$ )Nr   r   r   z, overload='r   r   z, attribute=r   r   r   r   r   zFunctionProto('r   )
r   overloadr   r   	attributer   r   r   r   r^   )r   r   r   r   r   r   r   r   s           rV   _function_proto_reprr     s#   {{dkk]!,}}!$--2yy#dii.)1~~"4>>"23		()B4CTCT)U(VWzzC

O,H5{{c$++./y9TYYKq
<.PVxXaWbcgbhhijjrf   c                n    U  Vs0 s H  oR                   UR                  _M     nn[        U5      $ s  snf N)r   versionrepr)protosr   opset_importss      rV   r   r     s2    >DEfU\\5==0fME Fs    2)rS   IO[bytes] | str | os.PathLikereturnr   )rT   r   rS   r   r   None)rS   z$IO[bytes] | str | os.PathLike | Noner   
str | Noner   )rm   _SupportedFormat | NonerS   z$str | os.PathLike | IO[bytes] | Noner   zserialization.ProtoSerializer)NT)rS   r   ru   r   rv   boolr   r#   )rS   r   ru   r   r   r2   )r}   zbytes | strru   _SupportedFormatr   r#   )r}   r   ru   r   r   r2   )r   zModelProto | bytesrS   r   ru   r   r   r   r   r   r   r   r   intr   r   r   r   )r   r2   rS   r   ru   r   r   r   )r   r#   r   r`   )r   r    r   r`   )r   r   r   r`   )r   zSequence[OperatorSetIdProto]r   r`   )`
__future__r   __all__ra   rP   rA   rB   onnxrC   onnx.onnx_cpp2py_exportr   onnx.external_data_helperr9   r@   r8   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.   r/   r0   r1   r2   r3   r4   r5   r6   r7   onnx.onnx_operators_pbr&   r(   onnx.onnx_data_pbr"   r*   r+   onnx.versionr   r   r   r   r   r   r   r   r   r   r   TYPE_CHECKINGcollections.abcrD   r   __version__r`   r   rl   rW   r\   re   rq   r;   r=   r:   r<   r>   r?   loadload_from_stringsaver   r   r   r   __repr__ rf   rV   <module>r      s  
 #BJ 
    + 
$ $ $ $ $ $ $ $ $ $J C D D     
(ll""
 EFL $ MQ+	 +%I+"+* '+#$#  	D '+W$W#W W*  /FFF F*  /GGG G, '+2
 #($(#22$2 $2
  2 "2 2 2 2 
2p '+$ $ 
	* ) @8V0k@ (
 '
 - rf   