
    QЦi?                     h   S SK Jr  S SKJrJrJrJrJr  S SKrS SKJ	r	J
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  S	SKJrJrJr  / SQr " S S5      r " S S\	R>                  5      r  " S S\	R>                  5      r! S,S\"S\#S\$S\$S\4
S jjr%S\\   S\&S\\   S\$S\S\!4S jr'S \S!.r( " S" S#\5      r) " S$ S%\5      r*\" 5       \" S&\)RV                  4S'9SS(S).S\\)   S\$S\S\!4S* jj5       5       r,\" 5       \" S&\*RV                  4S'9SS(S).S\\*   S\$S\S\!4S+ jj5       5       r-g)-    )partial)AnyCallableListOptionalSequenceN)nnTensor   )Conv2dNormActivationSqueezeExcitation)ImageClassification)_log_api_usage_once   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_make_divisible_ovewrite_named_paramhandle_legacy_interface)MobileNetV3MobileNet_V3_Large_WeightsMobileNet_V3_Small_Weightsmobilenet_v3_largemobilenet_v3_smallc                   ^    \ rS rSrS\S\S\S\S\S\S\S	\S
\4S jr\	S\S
\4S j5       r
Srg)InvertedResidualConfig   input_channelskernelexpanded_channelsout_channelsuse_se
activationstridedilation
width_multc
                     U R                  X5      U l        X l        U R                  X95      U l        U R                  XI5      U l        XPl        US:H  U l        Xpl        Xl        g )NHS)	adjust_channelsr    r!   r"   r#   r$   use_hsr&   r'   )
selfr    r!   r"   r#   r$   r%   r&   r'   r(   s
             ]/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/models/mobilenetv3.py__init__InvertedResidualConfig.__init__   s^     #22>N!%!5!56G!T 00J D(     channelsc                     [        X-  S5      $ )N   )r   )r2   r(   s     r.   r+   &InvertedResidualConfig.adjust_channels/   s    x4a88r1   )r'   r"   r    r!   r#   r&   r,   r$   N)__name__
__module____qualname____firstlineno__intboolstrfloatr/   staticmethodr+   __static_attributes__ r1   r.   r   r      s    !! ! 	!
 ! ! ! ! ! !* 9# 95 9 9r1   r   c            	          ^  \ rS rSr\" \\R                  S94S\S\	S\R                  4   S\	S\R                  4   4U 4S jjjrS\S	\4S
 jrSrU =r$ )InvertedResidual4   )scale_activationcnf
norm_layer.se_layerc                   > [         TU ]  5         SUR                  s=::  a  S::  d  O  [        S5      eUR                  S:H  =(       a    UR                  UR
                  :H  U l        / nUR                  (       a  [        R                  O[        R                  nUR                  UR                  :w  a0  UR                  [        UR                  UR                  SUUS95        UR                  S:  a  SOUR                  nUR                  [        UR                  UR                  UR                  UUR                  UR                  UUS95        UR                   (       a;  [#        UR                  S-  S5      nUR                  U" UR                  U5      5        UR                  [        UR                  UR
                  SUS S95        [        R$                  " U6 U l        UR
                  U l        UR                  S:  U l        g )Nr   r   zillegal stride valuekernel_sizerF   activation_layer)rJ   r&   r'   groupsrF   rK      r4   )superr/   r&   
ValueErrorr    r#   use_res_connectr,   r	   	HardswishReLUr"   appendr   r'   r!   r$   r   
Sequentialblock_is_cn)	r-   rE   rF   rG   layersrK   r&   squeeze_channels	__class__s	           r.   r/   InvertedResidual.__init__6   s    	SZZ$1$344"zzQY33E3EIYIY3Y"$+.::2<<277   C$6$66MM$&&)) !)%5 llQ&CJJ %%%%JJ,,%!1		
 ::.s/D/D/I1MMM(3#8#8:JKL 	 %%s'7'7QS]pt	
 ]]F+
,,jj1nr1   inputreturnc                 R    U R                  U5      nU R                  (       a  X!-  nU$ N)rU   rP   )r-   r[   results      r.   forwardInvertedResidual.forwardn   s%    E"OFr1   )rV   rU   r#   rP   )r6   r7   r8   r9   r   SElayerr	   Hardsigmoidr   r   Moduler/   r
   r`   r?   __classcell__rY   s   @r.   rB   rB   4   sl     .5Wr~~-^	6%#6% S"))^,6% 3		>*	6% 6%pV   r1   rB   c                      ^  \ rS rSr    SS\\   S\S\S\\S\	R                  4      S\\S\	R                  4      S	\S
\SS4U 4S jjjrS\S\4S jrS\S\4S jrSrU =r$ )r   u   Ninverted_residual_settinglast_channelnum_classesrU   .rF   dropoutkwargsr\   c                   > [         TU ]  5         [        U 5        U(       d  [        S5      e[	        U[
        5      (       a/  [        U Vs/ s H  n[	        U[        5      PM     sn5      (       d  [        S5      eUc  [        nUc  [        [        R                  SSS9n/ n	US   R                  n
U	R                  [        SU
SS	U[        R                   S
95        U H  nU	R                  U" X5      5        M     US   R"                  nSU-  nU	R                  [        UUSU[        R                   S95        [        R$                  " U	6 U l        [        R(                  " S5      U l        [        R$                  " [        R,                  " X5      [        R                   " SS9[        R.                  " USS9[        R,                  " X#5      5      U l        U R3                  5        GH  n[	        U[        R4                  5      (       ab  [        R6                  R9                  UR:                  SS9  UR<                  b+  [        R6                  R?                  UR<                  5        M  M  [	        U[        R                  [        R@                  45      (       aU  [        R6                  RC                  UR:                  5        [        R6                  R?                  UR<                  5        GM	  [	        U[        R,                  5      (       d  GM+  [        R6                  RE                  UR:                  SS5        [        R6                  R?                  UR<                  5        GM     gs  snf )a  
MobileNet V3 main class

Args:
    inverted_residual_setting (List[InvertedResidualConfig]): Network structure
    last_channel (int): The number of channels on the penultimate layer
    num_classes (int): Number of classes
    block (Optional[Callable[..., nn.Module]]): Module specifying inverted residual building block for mobilenet
    norm_layer (Optional[Callable[..., nn.Module]]): Module specifying the normalization layer to use
    dropout (float): The droupout probability
z1The inverted_residual_setting should not be emptyzDThe inverted_residual_setting should be List[InvertedResidualConfig]NgMbP?g{Gz?)epsmomentumr      r   )rJ   r&   rF   rK      r   rI   T)inplace)prt   fan_out)mode)#rN   r/   r   rO   
isinstancer   allr   	TypeErrorrB   r   r	   BatchNorm2dr    rS   r   rQ   r#   rT   featuresAdaptiveAvgPool2davgpoolLinearDropout
classifiermodulesConv2dinitkaiming_normal_weightbiaszeros_	GroupNormones_normal_)r-   ri   rj   rk   rU   rF   rl   rm   srW   firstconv_output_channelsrE   lastconv_input_channelslastconv_output_channelsmrY   s                  r.   r/   MobileNetV3.__init__v   s{   * 	D!(PQQ0(;;D]^D]qZ#9:D]^__bcc=$E UTJJ"$ %>a$@$O$O! )%!#		
 -CMM%01 - #<B"?"L"L#$'>#>  '(%!#	
 v.++A.--II.=LL&JJ$/IIl0	
 A!RYY''''y'A66%GGNN166* &A=>>ahh'qvv&Aryy))!T2qvv&  g _s   M.xc                     U R                  U5      nU R                  U5      n[        R                  " US5      nU R	                  U5      nU$ )Nr   )r|   r~   torchflattenr   r-   r   s     r.   _forward_implMobileNetV3._forward_impl   s@    MM!LLOMM!QOOAr1   c                 $    U R                  U5      $ r^   )r   r   s     r.   r`   MobileNetV3.forward   s    !!!$$r1   )r~   r   r|   )i  NNg?)r6   r7   r8   r9   r   r   r:   r   r   r	   rd   r=   r   r/   r
   r   r`   r?   re   rf   s   @r.   r   r   u   s    
  489=Y'#'(>#?Y' Y' 	Y'
 bii01Y' Xc299n56Y' Y' Y' 
Y' Y'vv & % %F % %r1   r   archr(   reduced_taildilatedrm   c                    U(       a  SOSnU(       a  SOSn[        [        US9n[        [        R                  US9nU S:X  a  U" SSSSSSSS5      U" SSS	S
SSSS5      U" S
SSS
SSSS5      U" S
SSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSU-  SSSU5      U" SU-  SSU-  SU-  SSSU5      U" SU-  SSU-  SU-  SSSU5      /n	U" SU-  5      n
X4$ U S:X  a  U" SSSSSSSS5      U" SSSS
SSSS5      U" S
SSS
SSSS5      U" S
SSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSSSSSSS5      U" SSS SU-  SSSU5      U" SU-  SS!U-  SU-  SSSU5      U" SU-  SS!U-  SU-  SSSU5      /n	U" S"U-  5      n
X4$ [        S#U  35      e)$Nr   r   )r(   r      rq   FRE@   r   H      (   Tx      P   r*         i  p   i     i  i   r   X   `   0      i   i@  i   zUnsupported model type )r   r   r+   rO   )r   r(   r   r   rm   reduce_dividerr'   
bneck_confr+   ri   rj   s              r.   _mobilenet_v3_confr      s:    'QANqH/JGJ4DDQ[\O##r1b"eT1a8r1b"eT1a8r1b"eT1a8r1b"dD!Q7r1c2tT1a8r1c2tT1a8r1c2udAq9r1c2udAq9r1c2udAq9r1c2udAq9r1c3dAq9sAsCtQ:sAsC>$94q(Ssn,a1F~H]_ceiklnvwsn,a1F~H]_ceiklnvw%
!" 't~'=>& %22% 
%	%r1b"dD!Q7r1b"eT1a8r1b"eT1a8r1b"dD!Q7r1c2tT1a8r1c2tT1a8r1c2tT1a8r1c2tT1a8r1c2#7tQQr^+Q~0Er^G[]acgijltur^+Q~0Er^G[]acgijltu%
! 't~'=> %22 24&9::r1   ri   rj   weightsprogressr\   c                     Ub#  [        US[        UR                  S   5      5        [        X40 UD6nUb  UR	                  UR                  USS95        U$ )Nrk   
categoriesT)r   
check_hash)r   lenmetar   load_state_dictget_state_dict)ri   rj   r   r   rm   models         r.   _mobilenet_v3r     s^     fmSl9S5TU1J6JEg44hSW4XYLr1   )r   r   )min_sizer   c                       \ rS rSr\" S\" \SS90 \ESSSSS	S
.0SSSS.ES9r\" S\" \SSS90 \ESSSSSS
.0SSSS.ES9r	\	r
Srg)r   i(  zChttps://download.pytorch.org/models/mobilenet_v3_large-8738ca79.pth   	crop_sizeiS ^https://github.com/pytorch/vision/tree/main/references/classification#mobilenetv3-large--smallImageNet-1Kg R@g(\V@zacc@1zacc@5g-?gw/5@zJThese weights were trained from scratch by using a simple training recipe.
num_paramsrecipe_metrics_ops
_file_size_docsurl
transformsr   zChttps://download.pytorch.org/models/mobilenet_v3_large-5c1a4163.pth   )r   resize_sizezHhttps://github.com/pytorch/vision/issues/3995#new-recipe-with-reg-tuninggK7R@gNbX9$W@gZd5@a/  
                These weights improve marginally upon the results of the original paper by using a modified version of
                TorchVision's `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            r@   N)r6   r7   r8   r9   r   r   r   _COMMON_METAIMAGENET1K_V1IMAGENET1K_V2DEFAULTr?   r@   r1   r.   r   r   (  s    Q.#>

!v##   e
M$ Q.#3O

!`##   
M, Gr1   r   c                   R    \ rS rSr\" S\" \SS90 \ESSSSS	S
.0SSSS.ES9r\r	Sr
g)r   iT  zChttps://download.pytorch.org/models/mobilenet_v3_small-047dcff4.pthr   r   i& r   r   gnP@g}?5^U@r   gv/?g r#@z}
                These weights improve upon the results of the original paper by using a simple training recipe.
            r   r   r@   N)r6   r7   r8   r9   r   r   r   r   r   r   r?   r@   r1   r.   r   r   T  sY    Q.#>

!v##  
M( Gr1   r   
pretrained)r   T)r   r   c                 `    [         R                  U 5      n [        S0 UD6u  p4[        X4X40 UD6$ )ao  
Constructs a large MobileNetV3 architecture from
`Searching for MobileNetV3 <https://arxiv.org/abs/1905.02244>`__.

Args:
    weights (:class:`~torchvision.models.MobileNet_V3_Large_Weights`, optional): The
        pretrained weights to use. See
        :class:`~torchvision.models.MobileNet_V3_Large_Weights` below for
        more details, and possible values. By default, no pre-trained
        weights are used.
    progress (bool, optional): If True, displays a progress bar of the
        download to stderr. Default is True.
    **kwargs: parameters passed to the ``torchvision.models.mobilenet.MobileNetV3``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/mobilenetv3.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.MobileNet_V3_Large_Weights
    :members:
)r   )r   verifyr   r   r   r   rm   ri   rj   s        r.   r   r   l  :    2 )//8G.@.`Y_.`+2'^W]^^r1   c                 `    [         R                  U 5      n [        S0 UD6u  p4[        X4X40 UD6$ )ao  
Constructs a small MobileNetV3 architecture from
`Searching for MobileNetV3 <https://arxiv.org/abs/1905.02244>`__.

Args:
    weights (:class:`~torchvision.models.MobileNet_V3_Small_Weights`, optional): The
        pretrained weights to use. See
        :class:`~torchvision.models.MobileNet_V3_Small_Weights` below for
        more details, and possible values. By default, no pre-trained
        weights are used.
    progress (bool, optional): If True, displays a progress bar of the
        download to stderr. Default is True.
    **kwargs: parameters passed to the ``torchvision.models.mobilenet.MobileNetV3``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/mobilenetv3.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.MobileNet_V3_Small_Weights
    :members:
)r   )r   r   r   r   r   s        r.   r   r     r   r1   )g      ?FF).	functoolsr   typingr   r   r   r   r   r   r	   r
   ops.miscr   r   rb   transforms._presetsr   utilsr   _apir   r   r   _metar   _utilsr   r   r   __all__r   rd   rB   r   r<   r=   r;   r   r:   r   r   r   r   r   r   r   r@   r1   r.   <module>r      s    : :   I 5 ' 6 6 ' S S9 98>ryy >Bg%")) g%V UZ.3
.3 .36:.3MQ.3eh.3b#$:; k" 	
  & &) )X 0 ,0J0X0X!YZ7;d_34_GK_^a__ [ _: ,0J0X0X!YZ7;d_34_GK_^a__ [ _r1   