Ë
    S^(h^  ã                   óÞ  — d Z ddlZddlmZmZmZ ddlZddl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mZ dd	lmZ dd
lmZmZmZmZ ddlmZ  ej8                  e«      ZdZdZ g d¢Z!dZ"dZ#dZ$dZ%dede&fd„Z'd2dee&ef   de(fd„Z) G d„ dejT                  «      Z+ G d„ dejX                  «      Z- G d„ dejT                  «      Z. G d„ d ejT                  «      Z/ G d!„ d"ejT                  «      Z0 G d#„ d$ejT                  «      Z1 G d%„ d&ejT                  «      Z2 G d'„ d(ejT                  «      Z3 G d)„ d*e«      Z4 ed+e$«       G d,„ d-e4«      «       Z5 ed.e$«       G d/„ d0e4«      «       Z6g d1¢Z7y)3zPyTorch EfficientNet model.é    N)ÚOptionalÚTupleÚUnion)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )ÚACT2FN)ÚBaseModelOutputWithNoAttentionÚ(BaseModelOutputWithPoolingAndNoAttentionÚ$ImageClassifierOutputWithNoAttention)ÚPreTrainedModel)Úadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingé   )ÚEfficientNetConfigr   zgoogle/efficientnet-b7)r   i   é   r   ztabby, tabby cataN  
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`EfficientNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
aB  
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`AutoImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
Ú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       út/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/efficientnet/modeling_efficientnet.pyÚround_filtersr"   P   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)   _   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!   r7   zEfficientNetEmbeddings.__init__x   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/   r;   r?   rA   )rC   rE   Úfeaturess      r!   ÚforwardzEfficientNetEmbeddings.forwardƒ   sA   € Ø—<‘< Ó-ˆØ×#Ñ# HÓ-ˆØ—>‘> (Ó+ˆØ—?‘? 8Ó,ˆàˆr#   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r7   ÚtorchÚTensorrJ   Ú__classcell__©rD   s   @r!   r+   r+   s   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$   r2   r/   ÚdilationÚgroupsr3   Úpadding_mode)r6   r7   )rC   rV   Údepth_multiplierr$   r2   r/   rX   r3   rZ   rW   rD   s             €r!   r7   z$EfficientNetDepthwiseConv2d.__init__�   s=   ø€ ð #Ð%5Ñ5ˆÜ‰ÑØ#Ø%Ø#ØØØØØØ%ð 	õ 
	
r#   )r   r
   r   r   r   TÚzeros)rK   rL   rM   r7   rQ   rR   s   @r!   rT   rT   Œ   s$   ø„ ð ØØØØØØ÷
ñ 
r#   rT   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_dimr8   r2   c                 óÜ   •— t         ‰| �  «        t        j                  ||ddd¬«      | _        t        j
                  ||j                  ¬«      | _        t        |j                     | _
        y )Nr   ÚsameF©rV   rW   r$   r/   r3   )Únum_featuresr4   )r6   r7   r   r:   Úexpand_convr<   r=   Ú	expand_bnr   r@   Ú
expand_act)rC   r   r_   r8   r2   rD   s        €r!   r7   z#EfficientNetExpansionLayer.__init__«   sZ   ø€ Ü‰ÑÔÜŸ9™9ØØ ØØØô
ˆÔô Ÿ™°WÀ&×BWÑBWÔXˆŒÜ  ×!2Ñ!2Ñ3ˆ�r#   Úhidden_statesrF   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S rH   )rd   re   rf   ©rC   rg   s     r!   rJ   z"EfficientNetExpansionLayer.forward·   s4   € à×(Ñ(¨Ó7ˆØŸ™ }Ó5ˆØŸ™¨Ó6ˆàÐr#   )rK   rL   rM   rN   r   r   r7   rO   ÚFloatTensorrP   rJ   rQ   rR   s   @r!   r^   r^   ¦   sH   ø„ ñð
4Ð1ð 
4¸3ð 
4Èð 
4ÐVYõ 
4ð U×%6Ñ%6ð ¸5¿<¹<÷ r#   r^   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   r_   r2   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   r0   ra   )r%   r.   Fr1   ©rc   r4   r5   )r6   r7   r2   r)   r   r9   Údepthwise_conv_padrT   Údepthwise_convr<   r=   r>   Údepthwise_normr   r@   Údepthwise_act)	rC   r   r_   r2   r$   rm   Úconv_padr/   rD   s	           €r!   r7   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#   rg   rF   c                 ó¬   — | j                   dk(  r| j                  |«      }| j                  |«      }| j                  |«      }| j	                  |«      }|S )Nr   )r2   rp   rq   rr   rs   ri   s     r!   rJ   z"EfficientNetDepthwiseLayer.forwardÛ   sT   € à�;‰;˜!ÒØ ×3Ñ3°MÓBˆMà×+Ñ+¨MÓ:ˆØ×+Ñ+¨MÓ:ˆØ×*Ñ*¨=Ó9ˆàÐr#   ©rK   rL   rM   rN   r   r   Úboolr7   rO   rj   rP   rJ   rQ   rR   s   @r!   rl   rl   À   sZ   ø„ ñð7à"ð7ð ð7ð ð	7ð
 ð7ð õ7ð,	 U×%6Ñ%6ð 	¸5¿<¹<÷ 	r#   rl   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   r_   Ú
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_sizera   )rV   rW   r$   r/   )r6   r7   Údimr   r   Úsqueeze_expansion_ratioÚdim_ser   ÚAdaptiveAvgPool2dÚsqueezer:   Úreducer{   r   r@   Ú
act_reduceÚSigmoidÚ
act_expand)rC   r   r_   rz   r{   rD   s        €r!   r7   z'EfficientNetSqueezeExciteLayer.__init__ì   s´   ø€ Ü‰ÑÔÙ!'‘:¨VˆŒÜ˜!œS ¨&×*HÑ*HÑ!HÓIÓJˆŒä×+Ñ+¸Ô:ˆŒÜ—i‘iØŸ™ØŸ™ØØô	
ˆŒô —i‘iØŸ™ØŸ™ØØô	
ˆŒô ! ×!2Ñ!2Ñ3ˆŒÜŸ*™*›,ˆ�r#   rg   rF   c                 óà   — |}| j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }| j	                  |«      }t        j                  ||«      }|S rH   )r‚   rƒ   r„   r{   r†   rO   Úmul)rC   rg   Úinputss      r!   rJ   z&EfficientNetSqueezeExciteLayer.forward  sc   € ØˆØŸ™ ]Ó3ˆØŸ™ MÓ2ˆØŸ™¨Ó6ˆàŸ™ MÓ2ˆØŸ™¨Ó6ˆÜŸ	™	 &¨-Ó8ˆàÐr#   )Frv   rR   s   @r!   ry   ry   ç   sH   ø„ ññ'Ð1ð '¸3ð 'ÈCð 'ÐY]õ 'ð*
 U×%6Ñ%6ð 
¸5¿<¹<÷ 
r#   ry   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   r_   r8   r2   Ú	drop_rateÚid_skipc                 ó  •— t         ‰| �  «        |dk(  xr | | _        t        j                  ||ddd¬«      | _        t        j                  ||j                  |j                  ¬«      | _	        t        j                  |¬«      | _        y )Nr   ra   Frb   ro   ©Úp)r6   r7   Úapply_dropoutr   r:   Úproject_convr<   r=   r>   Ú
project_bnÚDropoutÚdropout)rC   r   r_   r8   r2   rŒ   r�   rD   s          €r!   r7   z$EfficientNetFinalBlockLayer.__init__  sz   ø€ ô 	‰ÑÔØ# q™[Ò8°¨[ˆÔÜŸI™IØØ ØØØô
ˆÔô Ÿ.™.Ø  f×&;Ñ&;Àf×F`ÑF`ô
ˆŒô —z‘z IÔ.ˆ�r#   Ú
embeddingsrg   rF   c                 óŽ   — | j                  |«      }| j                  |«      }| j                  r| j                  |«      }||z   }|S rH   )r’   r“   r‘   r•   )rC   r–   rg   s      r!   rJ   z#EfficientNetFinalBlockLayer.forward$  sG   € Ø×)Ñ)¨-Ó8ˆØŸ™¨Ó6ˆà×ÒØ ŸL™L¨Ó7ˆMØ)¨JÑ6ˆMàÐr#   ©rK   rL   rM   rN   r   r   Úfloatrw   r7   rO   rj   rP   rJ   rQ   rR   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   r_   r8   r2   Úexpand_ratior$   rŒ   r�   rm   c
                 ót  •— t         ‰| �  «        || _        | j                  dk7  rdnd| _        ||z  }
| j                  rt	        |||
|¬«      | _        t        || j                  r|
n||||	¬«      | _        t        |||
| j                  ¬«      | _	        t        || j                  r|
n|||||¬«      | _        y )Nr   TF)r   r_   r8   r2   )r   r_   r2   r$   rm   )r   r_   rz   r{   )r   r_   r8   r2   rŒ   r�   )r6   r7   rœ   r{   r^   Ú	expansionrl   rq   ry   Úsqueeze_exciter‹   Ú
projection)rC   r   r_   r8   r2   rœ   r$   rŒ   r�   rm   Úexpand_in_dimrD   s              €r!   r7   zEfficientNetBlock.__init__J  s¾   ø€ ô 	‰ÑÔØ(ˆÔØ"×/Ñ/°1Ò4‘d¸%ˆŒØ Ñ-ˆà�;Š;Ü7Ø f°mÈFôˆDŒNô 9ØØ$(§K¢K‘=°VØØ#Ø)ô
ˆÔô =Ø &°]È4Ï;É;ô
ˆÔô 6ØØ$(§K¢K‘=°VØØØØô
ˆ�r#   rg   rF   c                 ó²   — |}| j                   dk7  r| j                  |«      }| j                  |«      }| j                  |«      }| j	                  ||«      }|S )Nr   )rœ   rž   rq   rŸ   r    )rC   rg   r–   s      r!   rJ   zEfficientNetBlock.forwards  s[   € Ø"ˆ
à×Ñ Ò!Ø ŸN™N¨=Ó9ˆMØ×+Ñ+¨MÓ:ˆð ×+Ñ+¨MÓ:ˆØŸ™¨
°MÓBˆØÐr#   r˜   rR   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e	   dee	   de
fd„Zˆ xZS )
ÚEfficientNetEncoderz§
    Forward propogates 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 ]k  }|dk(  rdnd}|dkD  rdn|	}	|dkD  r|n|}||j                  v rdnd}|j                  |z  |z  }t!        ||||	|
||||¬«	      }|j#                  |«       |dz  }Œm Œï 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 rH   )r   ÚmathÚceilÚdepth_coefficient)ÚrepeatsrC   s    €r!   Úround_repeatsz3EfficientNetEncoder.__init__.<locals>.round_repeatsŽ  s"   ø€ ä”t—y‘y ×!7Ñ!7¸'Ñ!AÓBÓCÐCr#   c              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wrH   © )Ú.0Únr«   s     €r!   ú	<genexpr>z/EfficientNetEncoder.__init__.<locals>.<genexpr>“  s   øè ø€ ÒL¨a™ q×)ÑLùs   ƒr   TFr   )	r   r_   r8   r2   r$   rœ   rŒ   r�   rm   i   ra   rb   ro   )r6   r7   r   r©   ÚlenrV   ÚsumÚnum_block_repeatsÚranger"   rW   ÚstridesÚkernel_sizesÚexpand_ratiosÚdepthwise_paddingÚdrop_connect_rater›   Úappendr   Ú
ModuleListÚblocksr:   Útop_convr<   Ú
hidden_dimr=   r>   Útop_bnr   r@   Útop_activation)rC   r   Únum_base_blocksÚ
num_blocksÚcurr_block_numr¼   Úir_   r8   r2   r$   rœ   Újr�   rm   rŒ   Úblockr«   rD   s   `                @€r!   r7   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™¨�Ø$%¨¢E™¨v�Ø*8¸F×<TÑ<TÑ*T¡ÐZ^�Ø"×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#   rg   Úoutput_hidden_statesÚreturn_dictrF   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rH   r­   )r®   Úvs     r!   r°   z.EfficientNetEncoder.forward.<locals>.<genexpr>Ò  s   è ø€ ÒX˜qÈ!É-œÑXùs   ‚Š)Úlast_hidden_staterg   )r¼   r½   r¿   rÀ   Útupler   )rC   rg   rÇ   rÈ   Úall_hidden_statesrÆ   s         r!   rJ   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)rK   rL   rM   rN   r   r7   rO   rj   r   rw   r   rJ   rQ   rR   s   @r!   r¤   r¤   €  sW   ø„ ñð58Ð1õ 58ðt 05Ø&*ñ	
à×(Ñ(ð
ð ' t™nð
ð ˜d‘^ð	
ð
 
(÷
r#   r¤   c                   ó&   — e Zd ZdZeZdZdZg Zd„ Z	y)ÚEfficientNetPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚefficientnetrE   c                 óú  — t        |t        j                  t        j                  f«      rm|j                  j
                  j                  d| j                  j                  ¬«       |j                  �%|j                  j
                  j                  «        yyt        |t        j                  «      rJ|j                  j
                  j                  «        |j                  j
                  j                  d«       yy)zInitialize the weightsg        )ÚmeanÚstdNg      ð?)r'   r   ÚLinearr:   ÚweightÚdataÚnormal_r   Úinitializer_ranger3   Úzero_Ú	LayerNormÚfill_)rC   Úmodules     r!   Ú_init_weightsz)EfficientNetPreTrainedModel._init_weightså  s¨   € ä�fœrŸy™y¬"¯)©)Ð4Ô5ð �M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)ð .r#   N)
rK   rL   rM   rN   r   Úconfig_classÚbase_model_prefixÚmain_input_nameÚ_no_split_modulesrÞ   r­   r#   r!   rÐ   rÐ   Ú  s$   „ ñð
 &€LØ&ÐØ$€OØÐó
*r#   rÐ   zUThe bare EfficientNet model outputting raw features without any specific head on top.c                   óª   ‡ — e Zd Zdefˆ fd„Z ee«       eee	e
de¬«      	 	 	 d
deej                     dee   dee   deee	f   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 )r6   r7   r   r+   r–   r¤   ÚencoderÚpooling_typer   Ú	AvgPool2dr¾   ÚpoolerÚ	MaxPool2dÚ
ValueErrorÚpoolingÚ	post_initrB   s     €r!   r7   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#   Úvision)Ú
checkpointÚoutput_typerß   ÚmodalityÚexpected_outputrE   rÇ   rÈ   rF   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_outputrg   )r   rÇ   Úuse_return_dictrì   r–   rç   rê   ÚreshapeÚshaper   rg   )rC   rE   rÇ   rÈ   Úembedding_outputÚencoder_outputsrÌ   Úpooled_outputs           r!   rJ   zEfficientNetModel.forward  sâ   € ð %9Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐÜÐ?Ó@Ð@àŸ?™?¨<Ó8ÐàŸ,™,ØØ!5Ø#ð 'ó 
ˆð ,¨AÑ.ÐØŸ™Ð$5Ó6ˆà%×-Ñ-¨m×.AÑ.AÀ"À1Ð.EÓFˆáØ% }Ð5¸ÈÈÐ8KÑKÐKä7Ø/Ø'Ø)×7Ñ7ô
ð 	
r#   )NNN)rK   rL   rM   r   r7   r   ÚEFFICIENTNET_INPUTS_DOCSTRINGr   Ú_CHECKPOINT_FOR_DOCr   Ú_CONFIG_FOR_DOCÚ_EXPECTED_OUTPUT_SHAPEr   rO   rj   rw   r   r   rJ   rQ   rR   s   @r!   rä   rä   ò  s–   ø„ ð
Ð1õ ñ" +Ð+HÓIÙØ&Ø<Ø$ØØ.ôð 59Ø/3Ø&*ñ	"
à˜u×0Ñ0Ñ1ð"
ð ' t™nð"
ð ˜d‘^ð	"
ð
 
ˆuÐ>Ð>Ñ	?ò"
óó Jô"
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.
    c                   óÂ   ‡ — e Zd Zˆ fd„Z ee«       eeee	e
¬«      	 	 	 	 d	deej                     deej                     dee   dee   deeef   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   )r6   r7   Ú
num_labelsr   rä   rÑ   r   r”   Údropout_rater•   rÕ   r¾   ÚIdentityÚ
classifierrî   rB   s     €r!   r7   z+EfficientNetForImageClassification.__init__=  s‡   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒØˆŒÜ-¨fÓ5ˆÔä—z‘z F×$7Ñ$7Ô8ˆŒØKOÏ?É?Ð]^ÒK^œ"Ÿ)™) F×$5Ñ$5°t·±ÔGÔdf×doÑdoÓdqˆŒð 	�‰Õr#   )rð   rñ   rß   ró   rE   ÚlabelsrÇ   rÈ   rF   c                 ó:  — |�|n| j                   j                  }| j                  |||¬«      }|r|j                  n|d   }| j	                  |«      }| j                  |«      }d}|��‡| j                   j                  €�| j                  dk(  rd| j                   _        nl| j                  dkD  rL|j                  t        j                  k(  s|j                  t        j                  k(  rd| j                   _        nd| j                   _        | j                   j                  dk(  rIt        «       }	| j                  dk(  r& |	|j                  «       |j                  «       «      }nŒ |	||«      }n‚| j                   j                  dk(  r=t        «       }	 |	|j                  d| j                  «      |j                  d«      «      }n,| j                   j                  dk(  rt!        «       }	 |	||«      }|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   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationéÿÿÿÿr   )ÚlossÚlogitsrg   )r   r÷   rÑ   rö   r•   r  Úproblem_typer  ÚdtyperO   Úlongr   r	   r‚   r   Úviewr   r   rg   )rC   rE   r  rÇ   rÈ   Úoutputsrü   r  r  Úloss_fctÚoutputs              r!   rJ   z*EfficientNetForImageClassification.forwardI  sÒ  € ð( &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà×#Ñ# LÐG[ÐitÐ#Óuˆá1<˜×-Ò-À'È!Á*ˆØŸ™ ]Ó3ˆØ—‘ Ó/ˆàˆØÑØ�{‰{×'Ñ'Ð/Ø—?‘? aÒ'Ø/;�D—K‘KÕ,Ø—_‘_ qÒ(¨f¯l©l¼e¿j¹jÒ.HÈFÏLÉLÔ\a×\eÑ\eÒLeØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—?‘? aÒ'Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# F¨FÓ3‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù §¡¨B°·±Ó @À&Ç+Á+ÈbÃ/ÓR‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨Ó/�áØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä3ØØØ!×/Ñ/ô
ð 	
r#   )NNNN)rK   rL   rM   r7   r   rý   r   Ú_IMAGE_CLASS_CHECKPOINTr   rÿ   Ú_IMAGE_CLASS_EXPECTED_OUTPUTr   rO   rj   Ú
LongTensorrw   r   r   rJ   rQ   rR   s   @r!   r  r  5  s£   ø„ ô
ñ +Ð+HÓIÙØ*Ø8Ø$Ø4ô	ð 59Ø-1Ø/3Ø&*ñ4
à˜u×0Ñ0Ñ1ð4
ð ˜×)Ñ)Ñ*ð4
ð ' t™nð	4
ð
 ˜d‘^ð4
ð 
ˆuÐ:Ð:Ñ	;ò4
óó Jô4
r#   r  )r  rä   rÐ   )T)8rN   r§   Útypingr   r   r   rO   Útorch.utils.checkpointr   Útorch.nnr   r   r	   Úactivationsr   Úmodeling_outputsr   r   r   Úmodeling_utilsr   Úutilsr   r   r   r   Úconfiguration_efficientnetr   Ú
get_loggerrK   Úloggerrÿ   rþ   r   r  r  ÚEFFICIENTNET_START_DOCSTRINGrý   r   r"   rw   r)   ÚModuler+   r:   rT   r^   rl   ry   r‹   r›   r¤   rÐ   rä   r  Ú__all__r­   r#   r!   ú<module>r'     s±  ðñ "ã ß )Ñ )ã Û Ý ß AÑ Aå !÷ñ õ
 .÷ó õ ;ð 
ˆ×	Ñ	˜HÓ	%€ð '€ð /Ð Ú'Ð ð 3Ð Ø1Ð ð	 Ð ð!Ð ðÐ,ð ¸Có ñ@˜U 3¨ :Ñ.ð @¸ó @ô(˜RŸY™Yô ô2
 "§)¡)ô 
ô4 §¡ô ô4$ §¡ô $ôN$ R§Y¡Yô $ôN "§)¡)ô ôBN˜Ÿ	™	ô NôbW
˜"Ÿ)™)ô W
ôt* /ô *ñ0 Ø[Ø óô<
Ð3ó <
ó	ð<
ñ~ ðð !óôH
Ð)Dó H
óðH
òV e�r#   