§
    \zniû.  ã                   óð  — d Z ddlZddlZddlmZmZmZmZmZ  G d„ dej	        ¦  «        Z
deee                  deee                  deee                  fd	„Zdeee                  deeee         ee         f                  dee         fd
„Zdeee                  deeee         ee         f                  dee         deee         ee         f         fd„Z G d„ d¦  «        Z G d„ d¦  «        ZdS )zB Collection of utils to be used by backbones and their components.é    N)ÚIterableÚListÚOptionalÚTupleÚUnionc                   ó   — e Zd ZdZdZdS )ÚBackboneTypeÚtimmÚtransformersN)Ú__name__Ú
__module__Ú__qualname__ÚTIMMÚTRANSFORMERS© ó    ú�/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/utils/backbone_utils.pyr	   r	      s   € € € € € Ø€DØ!€L€L€Lr   r	   Úout_featuresÚout_indicesÚstage_namesc                 óv  ‡— ‰€t          d¦  «        ‚| �et          | t          f¦  «        st          dt          | ¦  «        › �¦  «        ‚t	          ˆfd„| D ¦   «         ¦  «        rt          d‰› d| › �¦  «        ‚|�et          |t          t
          f¦  «        st          dt          |¦  «        › �¦  «        ‚t	          ˆfd„|D ¦   «         ¦  «        rt          d	¦  «        ‚| �R|�Rt          | ¦  «        t          |¦  «        k    rt          d
¦  «        ‚| ˆfd„|D ¦   «         k    rt          d¦  «        ‚dS dS dS )zW
    Verify that out_indices and out_features are valid for the given stage_names.
    Nz2Stage_names must be set for transformers backboneszout_features must be a list c              3   ó    •K  — | ]}|‰vV — Œ	d S ©Nr   )Ú.0Úfeatr   s     €r   ú	<genexpr>z2verify_out_features_out_indices.<locals>.<genexpr>(   s(   øè è € Ð@Ð@¨4ˆt˜;Ð&Ð@Ð@Ð@Ð@Ð@Ð@r   z.out_features must be a subset of stage_names: z got z)out_indices must be a list or tuple, got c              3   ó>   •K  — | ]}|t          ‰¦  «        k    V — Œd S r   ©Úlen©r   Úidxr   s     €r   r   z2verify_out_features_out_indices.<locals>.<genexpr>.   s0   øè è € Ð>Ð>¨3ˆs•c˜+Ñ&Ô&Ò&Ð>Ð>Ð>Ð>Ð>Ð>r   zRout_indices must be valid indices for stage_names {stage_names}, got {out_indices}zHout_features and out_indices should have the same length if both are setc                 ó    •— g | ]
}‰|         ‘ŒS r   r   r    s     €r   ú
<listcomp>z3verify_out_features_out_indices.<locals>.<listcomp>4   s   ø€ ÐDÐDÐD°˜K¨Ô,ÐDÐDÐDr   zQout_features and out_indices should correspond to the same stages if both are set)Ú
ValueErrorÚ
isinstanceÚlistÚtypeÚanyÚtupler   ©r   r   r   s     `r   Úverify_out_features_out_indicesr+      s†  ø€ ð ÐÝÐMÑNÔNÐNàÐÝ˜,­¨Ñ0Ô0ð 	RÝÐP½DÀÑ<NÔ<NÐPÐPÑQÔQÐQÝÐ@Ð@Ð@Ð@°<Ð@Ñ@Ô@Ñ@Ô@ð 	pÝÐnÈkÐnÐnÐ`lÐnÐnÑoÔoÐoàÐÝ˜+­­e }Ñ5Ô5ð 	^ÝÐ\ÍÈkÑIZÔIZÐ\Ð\Ñ]Ô]Ð]ÝÐ>Ð>Ð>Ð>°+Ð>Ñ>Ô>Ñ>Ô>ð 	sÝÐqÑrÔrÐràÐ KÐ$;Ýˆ|ÑÔ¥ KÑ 0Ô 0Ò0Ð0ÝÐgÑhÔhÐhØÐDÐDÐDÐD¸ÐDÑDÔDÒDÐDÝÐpÑqÔqÐqð	  ÐÐ$;Ð$;ð EÐDr   c                 ó˜   ‡— |€| €t          ‰¦  «        dz
  g}‰d         g} n%|€| �ˆfd„| D ¦   «         }n| €|�ˆfd„|D ¦   «         } | |fS )a‡  
    Finds the corresponding `out_features` and `out_indices` for the given `stage_names`.

    The logic is as follows:
        - `out_features` not set, `out_indices` set: `out_features` is set to the `out_features` corresponding to the
        `out_indices`.
        - `out_indices` not set, `out_features` set: `out_indices` is set to the `out_indices` corresponding to the
        `out_features`.
        - `out_indices` and `out_features` not set: `out_indices` and `out_features` are set to the last stage.
        - `out_indices` and `out_features` set: input `out_indices` and `out_features` are returned.

    Args:
        out_features (`List[str]`): The names of the features for the backbone to output.
        out_indices (`List[int]` or `Tuple[int]`): The indices of the features for the backbone to output.
        stage_names (`List[str]`): The names of the stages of the backbone.
    Né   éÿÿÿÿc                 ó:   •— g | ]}‰                      |¦  «        ‘ŒS r   )Úindex)r   Úlayerr   s     €r   r#   z9_align_output_features_output_indices.<locals>.<listcomp>Q   s'   ø€ ÐJÐJÐJ°E�{×(Ò(¨Ñ/Ô/ÐJÐJÐJr   c                 ó    •— g | ]
}‰|         ‘ŒS r   r   r    s     €r   r#   z9_align_output_features_output_indices.<locals>.<listcomp>S   s   ø€ Ð@Ð@Ð@¨S˜ CÔ(Ð@Ð@Ð@r   r   r*   s     `r   Ú%_align_output_features_output_indicesr3   8   sˆ   ø€ ð* Ð˜|Ð3Ý˜;Ñ'Ô'¨!Ñ+Ð,ˆØ# BœÐ(ˆˆØ	Ð	 Ð!9ØJÐJÐJÐJ¸\ÐJÑJÔJˆˆØ	Ð	 +Ð"9Ø@Ð@Ð@Ð@°KÐ@Ñ@Ô@ˆØ˜Ð$Ð$r   Úreturnc                 ó|   — t          | ||¬¦  «         t          | ||¬¦  «        \  }}t          |||¬¦  «         ||fS )a`  
    Get the `out_features` and `out_indices` so that they are aligned.

    The logic is as follows:
        - `out_features` not set, `out_indices` set: `out_features` is set to the `out_features` corresponding to the
        `out_indices`.
        - `out_indices` not set, `out_features` set: `out_indices` is set to the `out_indices` corresponding to the
        `out_features`.
        - `out_indices` and `out_features` not set: `out_indices` and `out_features` are set to the last stage.
        - `out_indices` and `out_features` set: they are verified to be aligned.

    Args:
        out_features (`List[str]`): The names of the features for the backbone to output.
        out_indices (`List[int]` or `Tuple[int]`): The indices of the features for the backbone to output.
        stage_names (`List[str]`): The names of the stages of the backbone.
    r*   )r+   r3   )r   r   r   Úoutput_featuresÚoutput_indicess        r   Ú*get_aligned_output_features_output_indicesr8   W   s]   € õ, $°È;ÐdoÐpÑpÔpÐpÝ&KØ!¨{Èð'ñ 'ô 'Ñ#€O�^õ $°ÈnÐjuÐvÑvÔvÐvØ˜NÐ*Ð*r   c                   óp  ‡ — e Zd ZU dZee         ed<   dd„Zdd„Zdd„Z	e
d„ ¦   «         Zej        dee         fd	„¦   «         Ze
d
„ ¦   «         Zej        deee         ee         f         fd„¦   «         Ze
d„ ¦   «         Ze
d„ ¦   «         Zd„ Z	 	 	 ddee         dee         dee         fd„Zˆ fd„Zˆ xZS )ÚBackboneMixinNÚbackbone_typer4   c                 óp  — t          | dd¦  «        €t          d¦  «        ‚d„ | j        j        j        D ¦   «         | _        d„ | j        j        j        D ¦   «         | _        | j        j        j        }| j        j                             ¦   «         }t          ||| j        ¬¦  «         ||c| _
        | _        dS )zo
        Initialize the backbone model from timm The backbone must already be loaded to self._backbone
        Ú	_backboneNz=self._backbone must be set before calling _init_timm_backbonec                 ó   — g | ]
}|d          ‘ŒS )Úmoduler   ©r   Ústages     r   r#   z5BackboneMixin._init_timm_backbone.<locals>.<listcomp>ƒ   s   € ÐZÐZÐZ°˜E (œOÐZÐZÐZr   c                 ó   — g | ]
}|d          ‘ŒS )Únum_chsr   r@   s     r   r#   z5BackboneMixin._init_timm_backbone.<locals>.<listcomp>„   s   € Ð\Ð\Ð\°%˜U 9Ô-Ð\Ð\Ð\r   r*   )Úgetattrr$   r=   Úfeature_infoÚinfor   Únum_featuresr   Úmodule_namer+   Ú_out_featuresÚ_out_indices)ÚselfÚconfigr   r   s       r   Ú_init_timm_backbonez!BackboneMixin._init_timm_backboney   sÄ   € õ �4˜ dÑ+Ô+Ð3ÝÐ\Ñ]Ô]Ð]ð
 [ÐZ¸¼Ô9TÔ9YÐZÑZÔZˆÔØ\Ð\¸4¼>Ô;VÔ;[Ð\Ñ\Ô\ˆÔØ”nÔ1Ô=ˆØ”~Ô2×>Ò>Ñ@Ô@ˆõ 	(Ø%°;ÈDÔL\ð	
ñ 	
ô 	
ð 	
ð 1=¸kÐ-ˆÔ˜DÔ-Ð-Ð-r   c                 óÄ   — t          |d¦  «        }t          |dd ¦  «        }t          |dd ¦  «        }|| _        t          |||¬¦  «        \  | _        | _        d | _        d S )Nr   r   r   r*   )rD   r   r8   rI   rJ   rG   )rK   rL   r   r   r   s        r   Ú_init_transformers_backbonez)BackboneMixin._init_transformers_backboneŽ   sq   € Ý˜f mÑ4Ô4ˆÝ˜v ~°tÑ<Ô<ˆÝ˜f m°TÑ:Ô:ˆà&ˆÔÝ0ZØ%°;ÈKð1
ñ 1
ô 1
Ñ-ˆÔ˜DÔ-ð !ˆÔÐÐr   c                 ód  — || _         t          |dd¦  «        | _        | j        rt          j        nt          j        | _        | j        t          j        k    r|                      |¦  «         dS | j        t          j        k    r|                      |¦  «         dS t          d| j        › d�¦  «        ‚)z¬
        Method to initialize the backbone. This method is called by the constructor of the base class after the
        pretrained model weights have been loaded.
        Úuse_timm_backboneFzbackbone_type z not supported.N)
rL   rD   rQ   r	   r   r   r;   rM   rO   r$   )rK   rL   s     r   Ú_init_backbonezBackboneMixin._init_backboneš   s®   € ð
 ˆŒå!(¨Ð1DÀeÑ!LÔ!LˆÔØ26Ô2HÐg�\Ô.Ð.ÍlÔNgˆÔàÔ¥Ô!2Ò2Ð2Ø×$Ò$ VÑ,Ô,Ð,Ð,Ð,ØÔ¥<Ô#<Ò<Ð<Ø×,Ò,¨VÑ4Ô4Ð4Ð4Ð4åÐQ¨dÔ.@ÐQÐQÐQÑRÔRÐRr   c                 ó   — | j         S r   ©rI   ©rK   s    r   r   zBackboneMixin.out_features«   ó   € àÔ!Ð!r   r   c                 óN   — t          |d| j        ¬¦  «        \  | _        | _        dS ©z€
        Set the out_features attribute. This will also update the out_indices attribute to match the new out_features.
        Nr*   ©r8   r   rI   rJ   ©rK   r   s     r   r   zBackboneMixin.out_features¯   ó4   € õ
 1[Ø%°4ÀTÔEUð1
ñ 1
ô 1
Ñ-ˆÔ˜DÔ-Ð-Ð-r   c                 ó   — | j         S r   ©rJ   rU   s    r   r   zBackboneMixin.out_indices¸   ó   € àÔ Ð r   r   c                 óN   — t          d|| j        ¬¦  «        \  | _        | _        dS ©z
        Set the out_indices attribute. This will also update the out_features attribute to match the new out_indices.
        Nr*   rY   ©rK   r   s     r   r   zBackboneMixin.out_indices¼   ó4   € õ
 1[Ø¨;ÀDÔDTð1
ñ 1
ô 1
Ñ-ˆÔ˜DÔ-Ð-Ð-r   c                 óD   ‡ — ˆ fd„t          ‰ j        ¦  «        D ¦   «         S )Nc                 ó2   •— i | ]\  }}|‰j         |         “ŒS r   )rG   )r   ÚirA   rK   s      €r   ú
<dictcomp>z6BackboneMixin.out_feature_channels.<locals>.<dictcomp>É   s'   ø€ ÐXÐXÐX±°°5��tÔ(¨Ô+ÐXÐXÐXr   )Ú	enumerater   rU   s   `r   Úout_feature_channelsz"BackboneMixin.out_feature_channelsÅ   s+   ø€ ð YÐXÐXÐX½IÀdÔFVÑ<WÔ<WÐXÑXÔXÐXr   c                 ó*   ‡ — ˆ fd„‰ j         D ¦   «         S )Nc                 ó*   •— g | ]}‰j         |         ‘ŒS r   )rh   )r   ÚnamerK   s     €r   r#   z*BackboneMixin.channels.<locals>.<listcomp>Í   s!   ø€ ÐNÐNÐN°D�Ô)¨$Ô/ÐNÐNÐNr   )r   rU   s   `r   ÚchannelszBackboneMixin.channelsË   s    ø€ àNÐNÐNÐN¸DÔ<MÐNÑNÔNÐNr   c                 óª   ‡— t          t          j        | j        ¦  «        j        ¦  «        Šˆfd„|                     ¦   «         D ¦   «         } | |i |¤ŽS )Nc                 ó$   •— i | ]\  }}|‰v ¯	||“ŒS r   r   )r   ÚkÚvÚ	signatures      €r   rf   z>BackboneMixin.forward_with_filtered_kwargs.<locals>.<dictcomp>Ñ   s$   ø€ ÐMÐMÐM¡D A q¸aÀ9¸n¸n˜1˜a¸n¸n¸nr   )ÚdictÚinspectrq   ÚforwardÚ
parametersÚitems)rK   ÚargsÚkwargsÚfiltered_kwargsrq   s       @r   Úforward_with_filtered_kwargsz*BackboneMixin.forward_with_filtered_kwargsÏ   sV   ø€ Ý�Ô*¨4¬<Ñ8Ô8ÔCÑDÔDˆ	ØMÐMÐMÐM¨F¯LªL©N¬NÐMÑMÔMˆØˆt�TÐ-˜_Ð-Ð-Ð-r   Úoutput_hidden_statesÚoutput_attentionsÚreturn_dictc                 ó    — t          d¦  «        ‚)Nz7This method should be implemented by the derived class.)ÚNotImplementedError)rK   Úpixel_valuesr{   r|   r}   s        r   rt   zBackboneMixin.forwardÔ   s   € õ "Ð"[Ñ\Ô\Ð\r   c                 ó¨   •— t          ¦   «                              ¦   «         }|                     d¦  «        |d<   |                     d¦  «        |d<   |S ©z¿
        Serializes this instance to a Python dictionary. Override the default `to_dict()` from `PretrainedConfig` to
        include the `out_features` and `out_indices` attributes.
        rI   r   rJ   r   ©ÚsuperÚto_dictÚpop©rK   ÚoutputÚ	__class__s     €r   r…   zBackboneMixin.to_dictÝ   óI   ø€ õ
 ‘”—’Ñ"Ô"ˆØ!'§¢¨OÑ!<Ô!<ˆˆ~ÑØ &§
¢
¨>Ñ :Ô :ˆˆ}ÑØˆr   )r4   N)NNN)r   r   r   r;   r   r	   Ú__annotations__rM   rO   rR   Úpropertyr   Úsetterr   Ústrr   r   r   Úintrh   rl   rz   Úboolrt   r…   Ú__classcell__©r‰   s   @r   r:   r:   v   sÖ  ø€ € € € € € Ø,0€M�8˜LÔ)Ð0Ð0Ñ0ðJð Jð Jð Jð*
!ð 
!ð 
!ð 
!ðSð Sð Sð Sð" ð"ð "ñ „Xð"ð Ôð
¨¨c¬ð 
ð 
ð 
ñ Ôð
ð ð!ð !ñ „Xð!ð Ôð
 u¨U°3¬Z¸¸c¼Ð-BÔ'Cð 
ð 
ð 
ñ Ôð
ð ðYð Yñ „XðYð
 ðOð Oñ „XðOð.ð .ð .ð 04Ø,0Ø&*ð]ð ]ð ' tœnð]ð $ Dœ>ð	]ð
 ˜d”^ð]ð ]ð ]ð ]ðð ð ð ð ð ð ð ð r   r:   c                   óÎ   ‡ — e Zd ZdZed„ ¦   «         Zej        dee         fd„¦   «         Zed„ ¦   «         Z	e	j        de
ee         ee         f         fd„¦   «         Z	ˆ fd„Zˆ xZS )	ÚBackboneConfigMixinzv
    A Mixin to support handling the `out_features` and `out_indices` attributes for the backbone configurations.
    c                 ó   — | j         S r   rT   rU   s    r   r   z BackboneConfigMixin.out_featuresí   rV   r   r   c                 óN   — t          |d| j        ¬¦  «        \  | _        | _        dS rX   rY   rZ   s     r   r   z BackboneConfigMixin.out_featuresñ   r[   r   c                 ó   — | j         S r   r]   rU   s    r   r   zBackboneConfigMixin.out_indicesú   r^   r   r   c                 óN   — t          d|| j        ¬¦  «        \  | _        | _        dS r`   rY   ra   s     r   r   zBackboneConfigMixin.out_indicesþ   rb   r   c                 ó¨   •— t          ¦   «                              ¦   «         }|                     d¦  «        |d<   |                     d¦  «        |d<   |S r‚   rƒ   r‡   s     €r   r…   zBackboneConfigMixin.to_dict  rŠ   r   )r   r   r   Ú__doc__rŒ   r   r�   r   rŽ   r   r   r   r�   r…   r‘   r’   s   @r   r”   r”   è   sä   ø€ € € € € ðð ð ð"ð "ñ „Xð"ð Ôð
¨¨c¬ð 
ð 
ð 
ñ Ôð
ð ð!ð !ñ „Xð!ð Ôð
 u¨U°3¬Z¸¸c¼Ð-BÔ'Cð 
ð 
ð 
ñ Ôð
ðð ð ð ð ð ð ð ð r   r”   )rš   Úenumrs   Útypingr   r   r   r   r   ÚEnumr	   rŽ   r�   r+   r3   r8   r:   r”   r   r   r   ú<module>rž      sê  ðð  IÐ Hà €€€Ø €€€Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9ð"ð "ð "ð "ð "�4”9ñ "ô "ð "ð
rØ˜8 Cœ=Ô)ðrØ8@ÀÈ#ÄÔ8OðrØ^fÐgoÐpsÔgtÔ^uðrð rð rð rð8%Ø˜4 œ9Ô%ð%à˜%  S¤	¨5°¬:Ð 5Ô6Ô7ð%ð �c”ð%ð %ð %ð %ð>+Ø˜4 œ9Ô%ð+à˜%  S¤	¨5°¬:Ð 5Ô6Ô7ð+ð �c”ð+ð ˆ4�Œ9�d˜3”iÐÔ ð	+ð +ð +ð +ð>oð oð oð oð oñ oô oð oðd'ð 'ð 'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'r   