Ë
    ÃÓ^jí5  ã                  óª  — U d Z ddlmZ ddlZddlZddlZddlmZm	Z	m
Z
 ddl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 	 ddlZd
ZddlmZ g d¢Zi Zded<   i Zded<   d d„Z  G d„ de	«      Z! G d„ de!¬«      Z"d!d"d„Z#	 d#	 	 	 	 	 d$d„Z$	 d#	 	 	 	 	 d%d„Z%d&d„Z&d'd„Z'	 	 d(	 	 	 	 	 	 	 	 	 d)d„Z(	 	 d*	 	 	 	 	 	 	 d+d„Z)d,d„Z*d-d„Z+y# e$ r dZY Œ†w xY w).aÜ  Module for serialization and deserialization of Albumentations transforms.

This module provides functionality to serialize transforms to JSON or YAML format and
deserialize them back. It implements the Serializable interface that allows transforms
to be converted to and from dictionaries, which can then be saved to disk or transmitted
over a network. This is particularly useful for saving augmentation pipelines and
restoring them later with the exact same configuration.
é    )ÚannotationsN)ÚABCÚABCMetaÚabstractmethod)ÚMappingÚSequence)ÚEnum)ÚPath)ÚAnyÚLiteralÚTextIO)ÚwarnTF)Ú__version__)Ú	from_dictÚloadÚsaveÚto_dictzdict[str, SerializableMeta]ÚSERIALIZABLE_REGISTRYÚNON_SERIALIZABLE_REGISTRYc                ód   — | j                  d«      }|dk(  s| j                  d«      s| S | |dz   d  S )Nú.éÿÿÿÿzalbumentations.é   )ÚrfindÚ
startswith)Úclass_fullnameÚsplit_indexs     úl/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/albumentations/core/serialization.pyÚshorten_class_namer   '   sD   € à ×&Ñ& sÓ+€Kð �bÒ × 9Ñ 9Ð:KÔ LØÐð ˜+¨™/Ð+Ð,Ð,ó    c                  óZ   ‡ — e Zd ZdZdˆ fd„Zedd„«       Zedd„«       Zed	d„«       Zˆ xZ	S )
ÚSerializableMetazÐA metaclass that is used to register classes in `SERIALIZABLE_REGISTRY` or `NON_SERIALIZABLE_REGISTRY`
    so they can be found later while deserializing transformation pipeline using classes full names.
    c                óÌ   •— t        ‰| �  | ||g|¢­i |¤Ž}|dk7  rHt        |vr@|j                  «       r|t        |j                  «       <   |S |t        |j                  «       <   |S )NÚSerializable)ÚsuperÚ__new__r   Úis_serializabler   Úget_class_fullnamer   )ÚclsÚnameÚbasesÚargsÚkwargsÚcls_objÚ	__class__s         €r   r&   zSerializableMeta.__new__8   sr   ø€ Ü‘'‘/ # t¨UÐD°TÒD¸VÑDˆØ�>Ò!¤c°Ñ&6Ø×&Ñ&Ô(ØFMÔ% g×&@Ñ&@Ó&BÑCð ˆð KRÔ)¨'×*DÑ*DÓ*FÑGØˆr    c                 ó   — y)NF© ©r)   s    r   r'   z SerializableMeta.is_serializableA   s   € àr    c                ó   — t        | «      S ©N)Úget_shortest_class_fullnamer2   s    r   r(   z#SerializableMeta.get_class_fullnameE   s   € ä*¨3Ó/Ð/r    c                ó   — i S r4   r1   r2   s    r   Ú_to_dictzSerializableMeta._to_dictI   s   € àˆ	r    )
r*   Ústrr+   ztuple[type, ...]r,   r   r-   r   Úreturnr"   ©r9   Úbool©r9   r8   ©r9   údict[str, Any])
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   Úclassmethodr'   r(   r7   Ú__classcell__)r/   s   @r   r"   r"   3   sI   ø„ ñõð òó ðð ò0ó ð0ð òó ôr    r"   c                  ó`   — e Zd Zeedd„«       «       Zeedd„«       «       Zedd„«       Zd	d
d„Zy)r$   c                ó   — t         ‚r4   ©ÚNotImplementedErrorr2   s    r   r'   zSerializable.is_serializableO   ó
   € ô "Ð!r    c                ó   — t         ‚r4   rG   r2   s    r   r(   zSerializable.get_class_fullnameT   rI   r    c                ó   — t         ‚r4   rG   )Úselfs    r   Úto_dict_privatezSerializable.to_dict_privateY   s   € ä!Ð!r    c                óô   — |dvrd|› d�}	 t        |«      ‚	 | j                  «       }t        |d
œS # t        $ r= |dk(  r‚ i }t        j                  d| › d| j
                  j                  › d�d¬	«       Y ŒNw xY w)a™  Take a transform pipeline and convert it to a serializable representation that uses only standard
        python data types: dictionaries, lists, strings, integers, and floats.

        Args:
            self (Serializable): A transform that should be serialized. If the transform doesn't implement the `to_dict`
                method and `on_not_implemented_error` equals to 'raise' then `NotImplementedError` is raised.
                If `on_not_implemented_error` equals to 'warn' then `NotImplementedError` will be ignored
                but no transform parameters will be serialized.
            on_not_implemented_error (str): `raise` or `warn`.

        >   r   Úraisez(Unknown on_not_implemented_error value: z . Supported values are: 'raise' rO   z2Got NotImplementedError while trying to serialize z;. Object arguments are not preserved. The transform class 'z`' needs to implement 'to_dict_private' or inherit from BasicTransform to be properly serialized.é   ©Ú
stacklevel)r   Ú	transform)Ú
ValueErrorrM   rH   Úwarningsr   r/   r?   r   )rL   Úon_not_implemented_errorÚmsgÚtransform_dicts       r   r   zSerializable.to_dict]   s¥   € ð $Ð+<Ñ<Ø<Ð=UÐ<VÐVvÐwˆCØÜ˜S“/Ð!ð	Ø!×1Ñ1Ó3ˆNô  +¸ÑHÐHøô #ò 
	Ø'¨7Ò2ØàˆNÜ�M‰MØDÀTÀFð K(Ø(,¯©×(?Ñ(?Ð'@ð A<ð=ð ÷	ð
	ús   ˜1 ±AA7Á6A7Nr:   r<   r=   ©rO   )rV   r8   r9   r>   )	r?   r@   rA   rC   r   r'   r(   rM   r   r1   r    r   r$   r$   N   sR   „ ØØò"ó ó ð"ð Øò"ó ó ð"ð ò"ó ð"õIr    r$   )Ú	metaclassc                ó$   — | j                  |«      S )a~  Take a transform pipeline and convert it to a serializable representation that uses only standard
    python data types: dictionaries, lists, strings, integers, and floats.

    Args:
        transform (Serializable): A transform that should be serialized. If the transform doesn't implement
            the `to_dict` method and `on_not_implemented_error` equals to 'raise' then `NotImplementedError` is raised.
            If `on_not_implemented_error` equals to 'warn' then `NotImplementedError` will be ignored
            but no transform parameters will be serialized.
        on_not_implemented_error (str): `raise` or `warn`.

    )r   )rS   rV   s     r   r   r   }   s   € ð ×ÑÐ5Ó6Ð6r    c                ó¬   — | j                  d«      t        v r=| d   }|€d|› d�}	 t        |«      ‚|j                  |«      }| €t        d|› d�«      ‚|S y )NÚ__class_fullname__r?   z6To deserialize a non-serializable transform with name z you need to pass a dict withz Non-serializable transform with z# was not found in `nonserializable`)Úgetr   rT   )rS   Únonserializabler*   rW   Úresult_transforms        r   Úinstantiate_nonserializablera   Œ   sy   € ð ‡}�}Ð)Ó*Ô.GÑGØ˜Ñ$ˆØÐ"ØJÈ4È&ÐPmÐnˆCØ@Ü˜S“/Ð!Ø*×.Ñ.¨tÓ4ÐØÐÜÐ?À¸vÐEhÐiÓjÐjØÐØr    c                óp  — t        «        | d   }t        ||«      }|r|S |d   }|j                  «       D ��ci c]  \  }}|dk7  sŒ||“Œ }}}d|vr|dvrt        d|› d�d¬«       d	|d<   t        t        |«         }d
|v r#|d
   D �	cg c]  }	t        d|	i|¬«      ‘Œ c}	|d
<    |di |¤ŽS c c}}w c c}	w )a›  Args:
    transform_dict: A dictionary with serialized transform pipeline.
    nonserializable (dict): A dictionary that contains non-serializable transforms.
        This dictionary is required when you are restoring a pipeline that contains non-serializable transforms.
        Keys in that dictionary should be named same as `name` arguments in respective transforms from
        a serialized pipeline.

    rS   r]   Úp)ÚComposeÚ
Sequentialz
Transform z; has no 'p' parameter in serialized data, defaulting to 0.5rP   rQ   g      à?Ú
transforms©r_   r1   )Úregister_additional_transformsra   Úitemsr   r   r   r   )
rX   r_   rS   Úlmbdr*   ÚkÚvr,   r)   Úts
             r   r   r   �   sä   € ô #Ô$Ø˜{Ñ+€IÜ& y°/ÓB€DÙØˆØÐ)Ñ*€DØ&Ÿ_™_Ó.×L‘T�Q˜°!Ð7KÓ2KˆAˆq‰DÐL€DÑLð �$�˜4Ð'@Ñ@Üˆz˜$˜ÐZÐ[ÐhiÕjØˆˆS‰	ä
Ô 2°4Ó 8Ñ
9€CØ�tÑØdhÐiuÑdvÖwÐ_`œi¨°aÐ(8È/ÖZÒwˆˆ\ÑÙ‰;�‰;Ðùó Mùò xs   ¸B-ÁB-Â	B3c                ó*   — | dvrt        d| › d�«      ‚y )N>   ÚjsonÚyamlzUnknown data_format z*. Supported formats are: 'json' and 'yaml')rT   )Údata_formats    r   Úcheck_data_formatrr   ¼   s&   € ØÐ*Ñ*ÜÐ/°¨}Ð<fÐgÓhÐhð +r    c                ó@  — t        | t        «      r-| j                  «       D ��ci c]  \  }}|t        |«      “Œ c}}S t        | t        «      r)t        | t
        «      s| D �cg c]  }t        |«      ‘Œ c}S t        | t        «      r| j                  S | S c c}}w c c}w )zxRecursively search for Enum objects and convert them to their value.
    Also handle any Mapping or Sequence types.
    )Ú
isinstancer   ri   Úserialize_enumr   r8   r	   Úvalue)Úobjrk   rl   s      r   ru   ru   Á   s|   € ô �#”wÔØ14·±³×=©¨¨A�”> !Ó$Ñ$Ó=Ð=Ü�#”xÔ ¬°C¼Ô)=Ø+.Ö/ a”˜qÕ!Ò/Ð/Ü" 3¬Ô-ˆ3�9‰9Ð6°3Ð6ùó >ùâ/s   ¤BÁ"Bc                ó  — t        |«       | j                  |¬«      }t        |«      }t        |t        t
        f«      rpt        |«      j                  d«      5 }|dk(  r,t        sd}t        |«      ‚t        j                  ||d¬«       n|dk(  rt        j                  ||«       ddd«       y|dk(  r,t        sd}t        |«      ‚t        j                  ||d¬«       y|dk(  rt        j                  ||d	¬
«       yy# 1 sw Y   yxY w)a   Serialize a transform pipeline and save it to either a file specified by a path or a file-like object
    in either JSON or YAML format.

    Args:
        transform (Serializable): The transform pipeline to serialize.
        filepath_or_buffer (Union[str, Path, TextIO]): The file path or file-like object to write the serialized
            data to.
            If a string is provided, it is interpreted as a path to a file. If a file-like object is provided,
            the serialized data will be written to it directly.
        data_format (str): The format to serialize the data in. Valid options are 'json' and 'yaml'.
            Defaults to 'json'.
        on_not_implemented_error (str): Determines the behavior if a transform does not implement the `to_dict` method.
            If set to 'raise', a `NotImplementedError` is raised. If set to 'warn', the exception is ignored, and
            no transform arguments are saved. Defaults to 'raise'.

    Raises:
        ValueError: If `data_format` is 'yaml' but PyYAML is not installed.

    )rV   Úwrp   z<You need to install PyYAML to save a pipeline in YAML formatF)Údefault_flow_stylero   NrP   )Úindent)rr   r   ru   rt   r8   r
   ÚopenÚyaml_availablerT   rp   Ú	safe_dumpro   Údump)rS   Úfilepath_or_bufferrq   rV   rX   ÚfrW   s          r   r   r   Ì   sö   € ô2 �kÔ"Ø×&Ñ&Ð@XÐ&ÓY€NÜ# NÓ3€Nô Ð$¤s¬D kÔ2ÜÐ$Ó%×*Ñ*¨3Ó/ð 	-°1Ø˜fÒ$Ý%ØX�CÜ$ S›/Ð)Ü—‘˜~¨qÀUÖKØ Ò&Ü—	‘	˜.¨!Ô,÷	-ð 	-ð 
˜Ò	ÝØPˆCÜ˜S“/Ð!Ü�‰�~Ð'9ÈeÖTØ	˜Ò	Ü�	‰	�.Ð"4¸QÖ?ð 
÷	-ð 	-ús   ÁAC?Ã?Dc                óÈ  — t        |«       t        | t        t        f«      rft        | «      j	                  «       5 }|dk(  rt        j                  |«      }n(t        sd}t        |«      ‚t        j                  |«      }ddd«       nC|dk(  rt        j                  | «      }n(t        sd}t        |«      ‚t        j                  | «      }t        |¬«      S # 1 sw Y   ŒxY w)a4  Load a serialized pipeline from a file or file-like object and construct a transform pipeline.

    Args:
        filepath_or_buffer (Union[str, Path, TextIO]): The file path or file-like object to read the serialized
            data from.
            If a string is provided, it is interpreted as a path to a file. If a file-like object is provided,
            the serialized data will be read from it directly.
        data_format (Literal["json", "yaml"]): The format of the serialized data.
            Defaults to 'json'.
        nonserializable (Optional[dict[str, Any]]): A dictionary that contains non-serializable transforms.
            This dictionary is required when restoring a pipeline that contains non-serializable transforms.
            Keys in the dictionary should be named the same as the `name` arguments in respective transforms
            from the serialized pipeline. Defaults to None.

    Returns:
        object: The deserialized transform pipeline.

    Raises:
        ValueError: If `data_format` is 'yaml' but PyYAML is not installed.

    ro   z<You need to install PyYAML to load a pipeline in yaml formatNrg   )rr   rt   r8   r
   r|   ro   r   r}   rT   rp   Ú	safe_loadr   )r€   rq   r_   r�   rX   rW   s         r   r   r   ü   sÅ   € ô4 �kÔ"äÐ$¤s¬D kÔ2ÜÐ$Ó%×*Ñ*Ó,ð 	3°Ø˜fÒ$Ü!%§¡¨1£‘å%ØX�CÜ$ S›/Ð)Ü!%§¡°Ó!2�÷	3ð 	3ð 
˜Ò	ÜŸ™Ð#5Ó6‰åØPˆCÜ˜S“/Ð!ÜŸ™Ð(:Ó;ˆä�^°_ÔEÐE÷!	3ð 	3ús   »ACÃC!c                 ó˜   — t         j                  j                  d«      �	 ddl} | j                  j
                  }yy# t        $ r Y yw xY w)z“Register transforms that are not imported directly into the `albumentations` module by checking
    the availability of optional dependencies.
    ÚtorchNr   )Ú	importlibÚutilÚ	find_specÚalbumentations.pytorchÚpytorchÚ
ToTensorV2ÚImportError)ÚalbumentationsÚ_s     r   rh   rh   ,  sM   € ô ‡~�~×Ñ Ó(Ð4ð	ã)ð ×&Ñ&×1Ñ1‰Að 5øô ò 	Ùð	ús   ¡= ½	A	ÁA	c                óN   — | j                   › d| j                  › �}t        |«      S )at  The function `get_shortest_class_fullname` takes a class object as input and returns its shortened
    full name.

    :param cls: The parameter `cls` is of type `Type[BasicCompose]`, which means it expects a class that
    is a subclass of `BasicCompose`
    :type cls: Type[BasicCompose]
    :return: a string, which is the shortened version of the full class name.
    r   )r@   r?   r   )r)   r   s     r   r5   r5   ;  s(   € ð Ÿ™Ð' q¨¯©¨Ð7€NÜ˜nÓ-Ð-r    )r   r8   r9   r8   rY   )rS   r$   rV   r8   r9   r>   r4   )rS   r>   r_   údict[str, Any] | Noner9   úSerializable | None)rX   r>   r_   r�   r9   r‘   )rq   úLiteral['json', 'yaml']r9   ÚNone)rw   r   r9   r   )ro   rO   )
rS   r$   r€   ústr | Path | TextIOrq   r’   rV   zLiteral['raise', 'warn']r9   r“   )ro   N)r€   r”   rq   r’   r_   r�   r9   Úobject)r9   r“   )r)   z	type[Any]r9   r8   ),rB   Ú
__future__r   Úimportlib.utilr†   ro   rU   Úabcr   r   r   Úcollections.abcr   r   Úenumr	   Úpathlibr
   Útypingr   r   r   r   rp   r}   rŒ   r�   r   Ú__all__r   Ú__annotations__r   r   r"   r$   r   ra   r   rr   ru   r   r   rh   r5   r1   r    r   ú<module>rŸ      st  ðòõ #ã Û Û ß ,Ñ ,ß -Ý Ý ß 'Ñ 'Ý ðÛà€Nõ
 'â
2€ð 68Ð Ð2Ó 7Ø9;Ð Ð6Ó ;ó	-ô�wô ô6,IÐ-õ ,Iô^7ð" .2ðØðà*ðð óð& .2ðØ"ðà*ðð óó>ió
7ð ,2Ø9@ð	-@Øð-@à+ð-@ð )ð-@ð 7ð	-@ð
 
ó-@ðd ,2Ø-1ð-FØ+ð-Fà(ð-Fð +ð-Fð ó	-Fó`ô
.øðC	 ò Ø‚Nðús   ÁC ÃCÃC