Ë
    ÛÓ^j¬O  ã                   óŠ  — d Z ddlZddlZddl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mZmZ d
dlmZ  ej(                  e«      Zdedefd„Zd+deez  defd„Z G d„ dej8                  «      Z G d„ dej<                  «      Z G d„ dej8                  «      Z  G d„ dej8                  «      Z! G d„ dej8                  «      Z" G d„ dej8                  «      Z# G d„ dej8                  «      Z$ G d „ d!ej8                  «      Z%e G d"„ d#e«      «       Z&e G d$„ d%e&«      «       Z' ed&¬'«       G d(„ d)e&«      «       Z(g d*¢Z)y),zPyTorch EfficientNet model.é    N)Únné   )Úinitialization)ÚACT2FN)ÚBaseModelOutputWithNoAttentionÚ(BaseModelOutputWithPoolingAndNoAttentionÚ$ImageClassifierOutputWithNoAttention)ÚPreTrainedModel)Úauto_docstringÚloggingé   )ÚEfficientNetConfigÚconfigÚnum_channelsc                 óª   — | j                   }|| j                  z  }t        |t        ||dz  z   «      |z  |z  «      }|d|z  k  r||z  }t        |«      S )z<
    Round number of filters based on depth multiplier.
    é   gÍÌÌÌÌÌì?)Údepth_divisorÚwidth_coefficientÚmaxÚint)r   r   ÚdivisorÚnew_dims       ú�/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/efficientnet/modeling_efficientnet.pyÚround_filtersr   $   sf   € ð ×"Ñ"€GØ�F×,Ñ,Ñ,€LÜ�'œ3˜|¨g¸©kÑ9Ó:¸gÑEÈÑOÓP€Gð ��|Ñ#Ò#Ø�7Ñˆäˆw‹<Ðó    Úkernel_sizeÚadjustc                 ó¢   — t        | t        «      r| | f} | d   dz  | d   dz  f}|r|d   dz
  |d   |d   dz
  |d   fS |d   |d   |d   |d   fS )aJ  
    Utility function to get the tuple padding value for the depthwise convolution.

    Args:
        kernel_size (`int` or `tuple`):
            Kernel size of the convolution layers.
        adjust (`bool`, *optional*, defaults to `True`):
            Adjusts padding value to apply to right and bottom sides of the input.
    r   r   r   )Ú
isinstancer   )r   r   Úcorrects      r   Úcorrect_padr!   3   s}   € ô �+œsÔ#Ø" KÐ0ˆà˜1‰~ Ñ" K°¡N°aÑ$7Ð8€GÙØ˜‘
˜Q‘ ¨¡
¨G°A©J¸©N¸GÀA¹JÐGÐGà˜‘
˜G A™J¨°©
°G¸A±JÐ?Ð?r   c                   ó`   ‡ — e Zd ZdZdefˆ fd„Zdej                  dej                  fd„Zˆ xZ	S )ÚEfficientNetEmbeddingszL
    A module that corresponds to the stem module of the original work.
    r   c                 óˆ  •— t         ‰| �  «        t        |d«      | _        t	        j
                  d¬«      | _        t	        j                  |j                  | j                  dddd¬«      | _	        t	        j                  | j                  |j                  |j                  ¬	«      | _        t        |j                     | _        y )
Né    )r   r   r   r   ©Úpaddingr   r   ÚvalidF©r   Ústrider'   Úbias)ÚepsÚmomentum)ÚsuperÚ__init__r   Úout_dimr   Ú	ZeroPad2dr'   ÚConv2dr   ÚconvolutionÚBatchNorm2dÚbatch_norm_epsÚbatch_norm_momentumÚ	batchnormr   Ú
hidden_actÚ
activation©Úselfr   Ú	__class__s     €r   r/   zEfficientNetEmbeddings.__init__L   s�   ø€ Ü‰ÑÔä$ V¨RÓ0ˆŒÜ—|‘|¨LÔ9ˆŒÜŸ9™9Ø×Ñ §¡¸1ÀQÐPWÐ^cô
ˆÔô Ÿ™¨¯©¸&×:OÑ:OÐZ`×ZtÑZtÔuˆŒÜ  ×!2Ñ!2Ñ3ˆ�r   Úpixel_valuesÚreturnc                 óŽ   — | j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }|S ©N)r'   r3   r7   r9   )r;   r=   Úfeaturess      r   ÚforwardzEfficientNetEmbeddings.forwardW   sA   € Ø—<‘< Ó-ˆØ×#Ñ# HÓ-ˆØ—>‘> (Ó+ˆØ—?‘? 8Ó,ˆàˆr   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r/   ÚtorchÚTensorrB   Ú__classcell__©r<   s   @r   r#   r#   G   s0   ø„ ñð	4Ð1õ 	4ð E§L¡Lð °U·\±\÷ r   r#   c                   ó.   ‡ — e Zd Z	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚEfficientNetDepthwiseConv2dc	                 ó@   •— ||z  }	t         ‰
| �  ||	|||||||¬«	       y )N)	Úin_channelsÚout_channelsr   r*   r'   ÚdilationÚgroupsr+   Úpadding_mode)r.   r/   )r;   rN   Údepth_multiplierr   r*   r'   rP   r+   rR   rO   r<   s             €r   r/   z$EfficientNetDepthwiseConv2d.__init__a   s=   ø€ ð #Ð%5Ñ5ˆÜ‰ÑØ#Ø%Ø#ØØØØØØ%ð 	õ 
	
r   )r   r   r   r   r   TÚzeros)rC   rD   rE   r/   rI   rJ   s   @r   rL   rL   `   s$   ø„ ð ØØØØØØ÷
ñ 
r   rL   c                   ól   ‡ — e Zd ZdZdedededefˆ fd„Zdej                  dej                  fd	„Z
ˆ xZS )
ÚEfficientNetExpansionLayerz_
    This corresponds to the expansion phase of each block in the original implementation.
    r   Úin_dimr0   r*   c                 óÜ   •— t         ‰| �  «        t        j                  ||ddd¬«      | _        t        j
                  ||j                  ¬«      | _        t        |j                     | _
        y )Nr   ÚsameF©rN   rO   r   r'   r+   )Únum_featuresr,   )r.   r/   r   r2   Úexpand_convr4   r5   Ú	expand_bnr   r8   Ú
expand_act)r;   r   rW   r0   r*   r<   s        €r   r/   z#EfficientNetExpansionLayer.__init__   sZ   ø€ Ü‰ÑÔÜŸ9™9ØØ ØØØô
ˆÔô Ÿ™°WÀ&×BWÑBWÔXˆŒÜ  ×!2Ñ!2Ñ3ˆ�r   Úhidden_statesr>   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S r@   )r\   r]   r^   ©r;   r_   s     r   rB   z"EfficientNetExpansionLayer.forward‹   s4   € à×(Ñ(¨Ó7ˆØŸ™ }Ó5ˆØŸ™¨Ó6ˆàÐr   )rC   rD   rE   rF   r   r   r/   rG   ÚFloatTensorrH   rB   rI   rJ   s   @r   rV   rV   z   sH   ø„ ñð
4Ð1ð 
4¸3ð 
4Èð 
4ÐVYõ 
4ð U×%6Ñ%6ð ¸5¿<¹<÷ r   rV   c            
       óp   ‡ — e Zd ZdZdededededef
ˆ fd„Zdej                  d	ej                  fd
„Zˆ xZS )ÚEfficientNetDepthwiseLayerzk
    This corresponds to the depthwise convolution phase of each block in the original implementation.
    r   rW   r*   r   Úadjust_paddingc                 ób  •— t         ‰| �  «        || _        | j                  dk(  rdnd}t        ||¬«      }t	        j
                  |¬«      | _        t        ||||d¬«      | _        t	        j                  ||j                  |j                  ¬«      | _        t        |j                     | _        y )	Nr   r(   rY   )r   r&   Fr)   ©r[   r,   r-   )r.   r/   r*   r!   r   r1   Údepthwise_conv_padrL   Údepthwise_convr4   r5   r6   Údepthwise_normr   r8   Údepthwise_act)	r;   r   rW   r*   r   re   Úconv_padr'   r<   s	           €r   r/   z#EfficientNetDepthwiseLayer.__init__™   sš   ø€ ô 	‰ÑÔØˆŒØ"Ÿk™k¨QÒ.‘7°FˆÜ˜k°.ÔAˆä"$§,¡,°wÔ"?ˆÔÜ9Ø °FÀHÐSXô
ˆÔô !Ÿn™nØ V×%:Ñ%:ÀV×E_ÑE_ô
ˆÔô $ F×$5Ñ$5Ñ6ˆÕr   r_   r>   c                 ó¬   — | j                   dk(  r| j                  |«      }| j                  |«      }| j                  |«      }| j	                  |«      }|S )Nr   )r*   rh   ri   rj   rk   ra   s     r   rB   z"EfficientNetDepthwiseLayer.forward¯   sT   € à�;‰;˜!ÒØ ×3Ñ3°MÓBˆMà×+Ñ+¨MÓ:ˆØ×+Ñ+¨MÓ:ˆØ×*Ñ*¨=Ó9ˆàÐr   ©rC   rD   rE   rF   r   r   Úboolr/   rG   rb   rH   rB   rI   rJ   s   @r   rd   rd   ”   sZ   ø„ ñð7à"ð7ð ð7ð ð	7ð
 ð7ð õ7ð,	 U×%6Ñ%6ð 	¸5¿<¹<÷ 	r   rd   c            	       ón   ‡ — e Zd ZdZd
dedededefˆ fd„Zdej                  dej                  fd	„Zˆ xZS )ÚEfficientNetSqueezeExciteLayerzl
    This corresponds to the Squeeze and Excitement phase of each block in the original implementation.
    r   rW   Ú
expand_dimÚexpandc                 óæ  •— t         ‰| �  «        |r|n|| _        t        dt	        ||j
                  z  «      «      | _        t        j                  d¬«      | _	        t        j                  | j                  | j                  dd¬«      | _        t        j                  | j                  | j                  dd¬«      | _        t        |j                     | _        t        j                   «       | _        y )Nr   )Úoutput_sizerY   )rN   rO   r   r'   )r.   r/   Údimr   r   Úsqueeze_expansion_ratioÚdim_ser   ÚAdaptiveAvgPool2dÚsqueezer2   Úreducers   r   r8   Ú
act_reduceÚSigmoidÚ
act_expand)r;   r   rW   rr   rs   r<   s        €r   r/   z'EfficientNetSqueezeExciteLayer.__init__À   s´   ø€ Ü‰ÑÔÙ!'‘:¨VˆŒÜ˜!œS ¨&×*HÑ*HÑ!HÓIÓJˆŒä×+Ñ+¸Ô:ˆŒÜ—i‘iØŸ™ØŸ™ØØô	
ˆŒô —i‘iØŸ™ØŸ™ØØô	
ˆŒô ! ×!2Ñ!2Ñ3ˆŒÜŸ*™*›,ˆ�r   r_   r>   c                 óà   — |}| j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }| j	                  |«      }t        j                  ||«      }|S r@   )rz   r{   r|   rs   r~   rG   Úmul)r;   r_   Úinputss      r   rB   z&EfficientNetSqueezeExciteLayer.forwardÕ   sc   € ØˆØŸ™ ]Ó3ˆØŸ™ MÓ2ˆØŸ™¨Ó6ˆàŸ™ MÓ2ˆØŸ™¨Ó6ˆÜŸ	™	 &¨-Ó8ˆàÐr   )Frn   rJ   s   @r   rq   rq   »   sH   ø„ ññ'Ð1ð '¸3ð 'ÈCð 'ÐY]õ 'ð*
 U×%6Ñ%6ð 
¸5¿<¹<÷ 
r   rq   c                   óŒ   ‡ — e Zd ZdZdedededededefˆ fd„Zd	e	j                  d
e	j                  de	j                  fd„Zˆ xZS )ÚEfficientNetFinalBlockLayerz[
    This corresponds to the final phase of each block in the original implementation.
    r   rW   r0   r*   Ú	drop_rateÚid_skipc                 ó  •— t         ‰| �  «        |dk(  xr | | _        t        j                  ||ddd¬«      | _        t        j                  ||j                  |j                  ¬«      | _	        t        j                  |¬«      | _        y )Nr   rY   FrZ   rg   ©Úp)r.   r/   Úapply_dropoutr   r2   Úproject_convr4   r5   r6   Ú
project_bnÚDropoutÚdropout)r;   r   rW   r0   r*   r„   r…   r<   s          €r   r/   z$EfficientNetFinalBlockLayer.__init__ç   sz   ø€ ô 	‰ÑÔØ# q™[Ò8°¨[ˆÔÜŸI™IØØ ØØØô
ˆÔô Ÿ.™.Ø  f×&;Ñ&;Àf×F`ÑF`ô
ˆŒô —z‘z IÔ.ˆ�r   Ú
embeddingsr_   r>   c                 óŽ   — | j                  |«      }| j                  |«      }| j                  r| j                  |«      }||z   }|S r@   )rŠ   r‹   r‰   r�   )r;   rŽ   r_   s      r   rB   z#EfficientNetFinalBlockLayer.forwardø   sG   € Ø×)Ñ)¨-Ó8ˆØŸ™¨Ó6ˆà×ÒØ ŸL™L¨Ó7ˆMØ)¨JÑ6ˆMàÐr   ©rC   rD   rE   rF   r   r   Úfloatro   r/   rG   rb   rH   rB   rI   rJ   s   @r   rƒ   rƒ   â   sj   ø„ ñð/Ø(ð/Ø25ð/Ø@Cð/ØMPð/Ø]bð/Ømqõ/ð" %×"3Ñ"3ð ÀE×DUÑDUð ÐZ_×ZfÑZf÷ r   rƒ   c                   ó€   ‡ — e Zd ZdZdededededededed	ed
efˆ fd„Zde	j                  de	j                  fd„Zˆ xZS )ÚEfficientNetBlocka�  
    This corresponds to the expansion and depthwise convolution phase of each block in the original implementation.

    Args:
        config ([`EfficientNetConfig`]):
            Model configuration class.
        in_dim (`int`):
            Number of input channels.
        out_dim (`int`):
            Number of output channels.
        stride (`int`):
            Stride size to be used in convolution layers.
        expand_ratio (`int`):
            Expand ratio to set the output dimensions for the expansion and squeeze-excite layers.
        kernel_size (`int`):
            Kernel size for the depthwise convolution layer.
        drop_rate (`float`):
            Dropout rate to be used in the final phase of each block.
        id_skip (`bool`):
            Whether to apply dropout and sum the final hidden states with the input embeddings during the final phase
            of each block. Set to `True` for the first block of each stage.
        adjust_padding (`bool`):
            Whether to apply padding to only right and bottom side of the input kernel before the depthwise convolution
            operation, set to `True` for inputs with odd input sizes.
    r   rW   r0   r*   Úexpand_ratior   r„   r…   re   c
                 ól  •— t         ‰| �  «        || _        | j                  dk7  | _        ||z  }
| j                  rt	        |||
|¬«      | _        t        || j                  r|
n||||	¬«      | _        t        |||
| j                  ¬«      | _	        t        || j                  r|
n|||||¬«      | _        y )Nr   )r   rW   r0   r*   )r   rW   r*   r   re   )r   rW   rr   rs   )r   rW   r0   r*   r„   r…   )r.   r/   r”   rs   rV   Ú	expansionrd   ri   rq   Úsqueeze_exciterƒ   Ú
projection)r;   r   rW   r0   r*   r”   r   r„   r…   re   Úexpand_in_dimr<   s              €r   r/   zEfficientNetBlock.__init__  sº   ø€ ô 	‰ÑÔØ(ˆÔØ×'Ñ'¨1Ñ,ˆŒØ Ñ-ˆà�;Š;Ü7Ø f°mÈFôˆDŒNô 9ØØ$(§K¢K‘=°VØØ#Ø)ô
ˆÔô =Ø &°]È4Ï;É;ô
ˆÔô 6ØØ$(§K¢K‘=°VØØØØô
ˆ�r   r_   r>   c                 ó²   — |}| j                   dk7  r| j                  |«      }| j                  |«      }| j                  |«      }| j	                  ||«      }|S )Nr   )r”   r–   ri   r—   r˜   )r;   r_   rŽ   s      r   rB   zEfficientNetBlock.forwardG  s[   € Ø"ˆ
à×Ñ Ò!Ø ŸN™N¨=Ó9ˆMØ×+Ñ+¨MÓ:ˆð ×+Ñ+¨MÓ:ˆØŸ™¨
°MÓBˆØÐr   r�   rJ   s   @r   r“   r“     sƒ   ø„ ñð4'
à"ð'
ð ð'
ð ð	'
ð
 ð'
ð ð'
ð ð'
ð ð'
ð ð'
ð õ'
ðR
 U×%6Ñ%6ð 
¸5¿<¹<÷ 
r   r“   c            	       óf   ‡ — e Zd ZdZdefˆ fd„Z	 	 d
dej                  dedz  dedz  de	fd	„Z
ˆ xZS )ÚEfficientNetEncoderz§
    Forward propagates the embeddings through each EfficientNet block.

    Args:
        config ([`EfficientNetConfig`]):
            Model configuration class.
    r   c                 óà  •‡ ‡— t         ‰‰ �  «        |‰ _        |j                  ‰ _        ˆ fd„Št	        |j
                  «      }t        ˆfd„|j                  D «       «      }d}g }t        |«      D ]å  }t        ||j
                  |   «      }t        ||j                  |   «      }|j                  |   }	|j                  |   }
|j                  |   }t         ‰|j                  |   «      «      D ]c  }|dk(  }|dkD  rdn|	}	|dkD  r|n|}||j                  v}|j                  |z  |z  }t!        ||||	|
||||¬«	      }|j#                  |«       |dz  }Œe Œç t%        j&                  |«      ‰ _        t%        j*                  t        |d«      ddd¬	«      ‰ _        t%        j.                  |j0                  |j2                  |j4                  ¬
«      ‰ _        t8        |j:                     ‰ _        y )Nc                 óZ   •— t        t        j                  ‰j                  | z  «      «      S r@   )r   ÚmathÚceilÚdepth_coefficient)Úrepeatsr;   s    €r   Úround_repeatsz3EfficientNetEncoder.__init__.<locals>.round_repeatsb  s"   ø€ ä”t—y‘y ×!7Ñ!7¸'Ñ!AÓBÓCÐCr   c              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wr@   © )Ú.0Únr£   s     €r   ú	<genexpr>z/EfficientNetEncoder.__init__.<locals>.<genexpr>g  s   øè ø€ ÒL¨a™ q×)ÑLùs   ƒr   r   )	r   rW   r0   r*   r   r”   r„   r…   re   i   rY   FrZ   rg   )r.   r/   r   r¡   ÚlenrN   ÚsumÚnum_block_repeatsÚranger   rO   ÚstridesÚkernel_sizesÚexpand_ratiosÚdepthwise_paddingÚdrop_connect_rater“   Úappendr   Ú
ModuleListÚblocksr2   Útop_convr4   Ú
hidden_dimr5   r6   Útop_bnr   r8   Útop_activation)r;   r   Únum_base_blocksÚ
num_blocksÚcurr_block_numr´   ÚirW   r0   r*   r   r”   Újr…   re   r„   Úblockr£   r<   s   `                @€r   r/   zEfficientNetEncoder.__init__]  sí  ú€ Ü‰ÑÔØˆŒØ!'×!9Ñ!9ˆÔô	Dô ˜f×0Ñ0Ó1ˆÜÓL°6×3KÑ3KÔLÓLˆ
àˆØˆÜ�Ó'ò 	$ˆAÜ" 6¨6×+=Ñ+=¸aÑ+@ÓAˆFÜ# F¨F×,?Ñ,?ÀÑ,BÓCˆGØ—^‘^ AÑ&ˆFØ ×-Ñ-¨aÑ0ˆKØ!×/Ñ/°Ñ2ˆLä™=¨×)AÑ)AÀ!Ñ)DÓEÓFò $�Ø˜q™&�Ø !še™¨�Ø$%¨¢E™¨v�Ø!/°v×7OÑ7OÐ!O�Ø"×4Ñ4°~ÑEÈ
ÑR�	ä)Ø!Ø!Ø#Ø!Ø +Ø!-Ø'Ø#Ø#1ô
�ð —‘˜eÔ$Ø !Ñ#‘ñ'$ð	$ô8 —m‘m FÓ+ˆŒÜŸ	™	ØÜ& v¨tÓ4ØØØô
ˆŒô —n‘nØ×*Ñ*°×0EÑ0EÐPV×PjÑPjô
ˆŒô % V×%6Ñ%6Ñ7ˆÕr   r_   Úoutput_hidden_statesNÚreturn_dictr>   c                 ó   — |r|fnd }| j                   D ]  } ||«      }|sŒ||fz  }Œ | j                  |«      }| j                  |«      }| j                  |«      }|st	        d„ ||fD «       «      S t        ||¬«      S )Nc              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr@   r¥   )r¦   Úvs     r   r¨   z.EfficientNetEncoder.forward.<locals>.<genexpr>¦  s   è ø€ ÒX˜qÈ!É-œÑXùs   ‚Š)Úlast_hidden_stater_   )r´   rµ   r·   r¸   Útupler   )r;   r_   r¿   rÀ   Úall_hidden_statesr¾   s         r   rB   zEfficientNetEncoder.forward”  s›   € ñ 1E˜]Ñ,È$Ðà—[‘[ò 	6ˆEÙ! -Ó0ˆMÚ#Ø! mÐ%5Ñ5Ñ!ð	6ð
 Ÿ™ mÓ4ˆØŸ™ MÓ2ˆØ×+Ñ+¨MÓ:ˆáÜÑX ]Ð4EÐ$FÔXÓXÐXä-Ø+Ø+ô
ð 	
r   )FT)rC   rD   rE   rF   r   r/   rG   rb   ro   r   rB   rI   rJ   s   @r   rœ   rœ   T  sW   ø„ ñð58Ð1õ 58ðt -2Ø#'ñ	
à×(Ñ(ð
ð # T™kð
ð ˜D‘[ð	
ð
 
(÷
r   rœ   c                   ó~   ‡ — e Zd ZU eed<   dZdZdZdgZ e	j                  «       dej                  fˆ fd„«       Zˆ xZS )ÚEfficientNetPreTrainedModelr   Úefficientnetr=   )Úimager“   Úmodulec                 ó0  •— t         ‰| �  |«       t        |t        j                  t        j
                  t        j                  f«      rÍt        j                  |j                  d| j                  j                  ¬«       |j                  �t        j                  |j                  «       t        |dd«      �^t        j                  |j                  «       t        j                   |j"                  «       t        j                  |j$                  «       yyy)zInitialize the weightsg        )ÚmeanÚstdNÚrunning_mean)r.   Ú_init_weightsr   r   ÚLinearr2   r4   ÚinitÚnormal_Úweightr   Úinitializer_ranger+   Úzeros_ÚgetattrrÏ   Úones_Úrunning_varÚnum_batches_tracked)r;   rË   r<   s     €r   rÐ   z)EfficientNetPreTrainedModel._init_weights¶  s¸   ø€ ô 	‰Ñ˜fÔ%Ü�fœrŸy™y¬"¯)©)´R·^±^ÐDÔEÜ�L‰L˜Ÿ™¨S°d·k±k×6SÑ6SÕTØ�{‰{Ð&Ü—‘˜FŸK™KÔ(Ü�v˜~¨tÓ4Ð@Ü—‘˜F×/Ñ/Ô0Ü—
‘
˜6×-Ñ-Ô.Ü—‘˜F×6Ñ6Õ7ð Að	 Fr   )rC   rD   rE   r   Ú__annotations__Úbase_model_prefixÚmain_input_nameÚinput_modalitiesÚ_no_split_modulesrG   Úno_gradr   ÚModulerÐ   rI   rJ   s   @r   rÈ   rÈ   ®  sH   ø… àÓØ&ÐØ$€OØ!ÐØ,Ð-Ðà€U‡]�]ƒ_ð
8 B§I¡Iô 
8ó ô
8r   rÈ   c                   óz   ‡ — e Zd Zdefˆ fd„Ze	 	 	 d	dej                  dz  dedz  dedz  de	e
z  fd„«       Zˆ xZS )
ÚEfficientNetModelr   c                 óš  •— t         ‰| �  |«       || _        t        |«      | _        t        |«      | _        |j                  dk(  r't        j                  |j                  d¬«      | _        nN|j                  dk(  r't        j                  |j                  d¬«      | _        nt        d|j                  › �«      ‚| j                  «        y )NrÍ   T)Ú	ceil_moder   z2config.pooling must be one of ['mean', 'max'] got )r.   r/   r   r#   rŽ   rœ   ÚencoderÚpooling_typer   Ú	AvgPool2dr¶   ÚpoolerÚ	MaxPool2dÚ
ValueErrorÚpoolingÚ	post_initr:   s     €r   r/   zEfficientNetModel.__init__Æ  s¤   ø€ Ü‰Ñ˜Ô ØˆŒÜ0°Ó8ˆŒÜ*¨6Ó2ˆŒð ×Ñ &Ò(ÜŸ,™, v×'8Ñ'8ÀDÔIˆD�KØ× Ñ  EÒ)ÜŸ,™, v×'8Ñ'8ÀDÔIˆD�KäÐQÐRX×R`ÑR`ÐQaÐbÓcÐcð 	�‰Õr   Nr=   r¿   rÀ   r>   c                 ó~  — |�|n| j                   j                  }|�|n| j                   j                  }|€t        d«      ‚| j	                  |«      }| j                  |||¬«      }|d   }| j                  |«      }|j                  |j                  d d «      }|s
||f|dd  z   S t        |||j                  ¬«      S )Nz You have to specify pixel_values©r¿   rÀ   r   r   r   )rÄ   Úpooler_outputr_   )r   r¿   rÀ   rë   rŽ   ræ   ré   ÚreshapeÚshaper   r_   )	r;   r=   r¿   rÀ   ÚkwargsÚembedding_outputÚencoder_outputsrÄ   Úpooled_outputs	            r   rB   zEfficientNetModel.forward×  sâ   € ð %9Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆàÐÜÐ?Ó@Ð@àŸ?™?¨<Ó8ÐàŸ,™,ØØ!5Ø#ð 'ó 
ˆð ,¨AÑ.ÐØŸ™Ð$5Ó6ˆà%×-Ñ-¨m×.AÑ.AÀ"À1Ð.EÓFˆáØ% }Ð5¸ÈÈÐ8KÑKÐKä7Ø/Ø'Ø)×7Ñ7ô
ð 	
r   )NNN)rC   rD   rE   r   r/   r   rG   rb   ro   rÅ   r   rB   rI   rJ   s   @r   rã   rã   Ä  sn   ø„ ðÐ1õ ð" ð 26Ø,0Ø#'ñ	#
à×'Ñ'¨$Ñ.ð#
ð # T™kð#
ð ˜D‘[ð	#
ð 
Ð9Ñ	9ò#
ó ô#
r   rã   zŒ
    EfficientNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g.
    for ImageNet.
    )Úcustom_introc                   ó”   ‡ — e Zd Zˆ fd„Ze	 	 	 	 d	dej                  dz  dej                  dz  dedz  dedz  de	e
z  f
d„«       Zˆ xZS )
Ú"EfficientNetForImageClassificationc                 ó‚  •— t         ‰| �  |«       |j                  | _        || _        t	        |«      | _        t        j                  |j                  ¬«      | _	        | j                  dkD  r*t        j                  |j                  | j                  «      nt        j                  «       | _        | j                  «        y )Nr‡   r   )r.   r/   Ú
num_labelsr   rã   rÉ   r   rŒ   Údropout_rater�   rÑ   r¶   ÚIdentityÚ
classifierrí   r:   s     €r   r/   z+EfficientNetForImageClassification.__init__  s‡   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒØˆŒÜ-¨fÓ5ˆÔä—z‘z F×$7Ñ$7Ô8ˆŒØKOÏ?É?Ð]^ÒK^œ"Ÿ)™) F×$5Ñ$5°t·±ÔGÔdf×doÑdoÓdqˆŒð 	�‰Õr   Nr=   Úlabelsr¿   rÀ   r>   c                 ód  — |�|n| j                   j                  }| j                  |||¬«      }|r|j                  n|d   }| j	                  |«      }| j                  |«      }d}	|�| j                  ||| j                   «      }	|s|f|dd z   }
|	�|	f|
z   S |
S t        |	||j                  ¬«      S )aŠ  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        Nrï   r   r   )ÚlossÚlogitsr_   )	r   rÀ   rÉ   rð   r�   rþ   Úloss_functionr	   r_   )r;   r=   rÿ   r¿   rÀ   ró   Úoutputsrö   r  r  Úoutputs              r   rB   z*EfficientNetForImageClassification.forward  sÍ   € ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆà×#Ñ# LÐG[ÐitÐ#Óuˆá1<˜×-Ò-À'È!Á*ˆØŸ™ ]Ó3ˆØ—‘ Ó/ˆàˆØÐØ×%Ñ% f¨f°d·k±kÓBˆDáØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä3ØØØ!×/Ñ/ô
ð 	
r   )NNNN)rC   rD   rE   r/   r   rG   rb   Ú
LongTensorro   rÅ   r	   rB   rI   rJ   s   @r   rù   rù   þ  s~   ø„ ô
ð ð 26Ø*.Ø,0Ø#'ñ"
à×'Ñ'¨$Ñ.ð"
ð × Ñ  4Ñ'ð"
ð # T™kð	"
ð
 ˜D‘[ð"
ð 
Ð5Ñ	5ò"
ó ô"
r   rù   )rù   rã   rÈ   )T)*rF   rŸ   rG   r   Ú r   rÒ   Úactivationsr   Úmodeling_outputsr   r   r	   Úmodeling_utilsr
   Úutilsr   r   Úconfiguration_efficientnetr   Ú
get_loggerrC   Úloggerr   r   rÅ   ro   r!   rá   r#   r2   rL   rV   rd   rq   rƒ   r“   rœ   rÈ   rã   rù   Ú__all__r¥   r   r   ú<module>r     s`  ðñ "ã ã Ý å &Ý !÷ñ õ
 .ß ,Ý :ð 
ˆ×	Ñ	˜HÓ	%€ðÐ,ð ¸Có ñ@˜S 5™[ð @°$ó @ô(˜RŸY™Yô ô2
 "§)¡)ô 
ô4 §¡ô ô4$ §¡ô $ôN$ R§Y¡Yô $ôN "§)¡)ô ôBN˜Ÿ	™	ô NôbW
˜"Ÿ)™)ô W
ðt ô8 /ó 8ó ð8ð* ô6
Ð3ó 6
ó ð6
ñr ðôô0
Ð)Dó 0
óð0
òf e�r   