
    QЦi$                        S SK Jr  S SK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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  S	SKJrJrJrJrJ r   SSK!J"r"J#r#  / SQr$ " S S\5      r% " S S\5      r& " S S\ 5      r'S\\   S\(S\\   S\)S\)S\S\'4S jr* " S S \5      r+\" S!S"9\" S#S$ 4S%9SS&S'S(.S\\\+\4      S\)S\)S\S\'4
S) jj5       5       r,g)*    )partial)AnyListOptionalUnionN)nnTensor)DeQuantStub	QuantStub   )Conv2dNormActivationSqueezeExcitation)ImageClassification   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)_mobilenet_v3_confInvertedResidualInvertedResidualConfigMobileNet_V3_Large_WeightsMobileNetV3   )_fuse_modules_replace_relu)QuantizableMobileNetV3#MobileNet_V3_Large_QuantizedWeightsmobilenet_v3_largec                   v   ^  \ rS rSrSrS\S\SS4U 4S jjrS\S\4S	 jrSS
\	\
   SS4S jjrU 4S jrSrU =r$ )QuantizableSqueezeExcitation   r   argskwargsreturnNc                    > [         R                  US'   [        TU ]  " U0 UD6  [         R                  R                  5       U l        g )Nscale_activation)r   Hardsigmoidsuper__init__	quantizedFloatFunctionalskip_mulselfr%   r&   	__class__s      j/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/models/quantization/mobilenetv3.pyr,   %QuantizableSqueezeExcitation.__init__!   s8    %'^^!"$)&)446    inputc                 X    U R                   R                  U R                  U5      U5      $ N)r/   mul_scale)r1   r6   s     r3   forward$QuantizableSqueezeExcitation.forward&   s"    }}  U!3U;;r5   is_qatc                      [        U SS/USS9  g )Nfc1
activationTinplace)r   )r1   r=   s     r3   
fuse_model'QuantizableSqueezeExcitation.fuse_model)   s    dUL164Hr5   c           	        > UR                  SS 5      n[        U S5      (       a  Ub  US:  a  [        R                  " S/5      [        R                  " S/5      [        R                  " S/[        R                  S9[        R                  " S/[        R                  S9[        R                  " S/5      [        R                  " S/5      S.n	U	R                  5        H  u  pX*-   nX;  d  M  XU'   M     [        TU ]  UUUUUUU5        g )	Nversionqconfigr   g      ?r   )dtyper   )z.scale_activation.activation_post_process.scalezFscale_activation.activation_post_process.activation_post_process.scalez3scale_activation.activation_post_process.zero_pointzKscale_activation.activation_post_process.activation_post_process.zero_pointz;scale_activation.activation_post_process.fake_quant_enabledz9scale_activation.activation_post_process.observer_enabled)gethasattrtorchtensorint32itemsr+   _load_from_state_dict)r1   
state_dictprefixlocal_metadatastrictmissing_keysunexpected_keys
error_msgsrF   default_state_dictkvfull_keyr2   s                r3   rO   2QuantizableSqueezeExcitation._load_from_state_dict,   s     !$$Y54##GaKBG,,PSuBUZ_ZfZfhkglZmGL||UVTW_d_j_jGk_d_k_kCu{{` PU||]^\_O`MR\\[\Z]M^	" +002!:-+,x( 3
 	%	
r5   )r/   r8   )__name__
__module____qualname____firstlineno___versionr   r,   r	   r;   r   boolrC   rO   __static_attributes____classcell__r2   s   @r3   r#   r#      sY    H7c 7S 7T 7
<V < <I$ I4 I$
 $
r5   r#   c                   J   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrS	rU =r	$ )
QuantizableInvertedResidualS   r%   r&   r'   Nc                 x   > [         TU ]  " US[        0UD6  [        R                  R                  5       U l        g )Nse_layer)r+   r,   r#   r   r-   r.   skip_addr0   s      r3   r,   $QuantizableInvertedResidual.__init__U   s/    $P)EPP446r5   xc                     U R                   (       a*  U R                  R                  XR                  U5      5      $ U R                  U5      $ r8   )use_res_connectrj   addblockr1   rl   s     r3   r;   #QuantizableInvertedResidual.forwardY   s6    ==$$Q

166::a= r5   )rj   )
r\   r]   r^   r_   r   r,   r	   r;   rb   rc   rd   s   @r3   rf   rf   S   s5    7c 7S 7T 7! !F ! !r5   rf   c                   f   ^  \ rS rSrS\S\SS4U 4S jjrS\S\4S jrSS	\\	   SS4S
 jjr
SrU =r$ )r   `   r%   r&   r'   Nc                 b   > [         TU ]  " U0 UD6  [        5       U l        [	        5       U l        g)zQ
MobileNet V3 main class

Args:
   Inherits args from floating point MobileNetV3
N)r+   r,   r   quantr
   dequantr0   s      r3   r,   QuantizableMobileNetV3.__init__a   s)     	$)&)[
"}r5   rl   c                 l    U R                  U5      nU R                  U5      nU R                  U5      nU$ r8   )rv   _forward_implrw   rq   s     r3   r;   QuantizableMobileNetV3.forwardl   s1    JJqMq!LLOr5   r=   c                 @   U R                  5        H  n[        U5      [        L aP  SS/n[        U5      S:X  a0  [        US   5      [        R
                  L a  UR                  S5        [        X#USS9  Me  [        U5      [        L d  My  UR                  U5        M     g )N01r   r   2TrA   )
modulestyper   lenr   ReLUappendr   r#   rC   )r1   r=   mmodules_to_fuses       r3   rC   !QuantizableMobileNetV3.fuse_modelr   sy    AAw..#&*q6Q;4!:#8#**3/a&$Ga88V$  r5   )rw   rv   r8   )r\   r]   r^   r_   r   r,   r	   r;   r   ra   rC   rb   rc   rd   s   @r3   r   r   `   sL    	%c 	%S 	%T 	% F %$ %4 % %r5   r   inverted_residual_settinglast_channelweightsprogressquantizer&   r'   c                    UbM  [        US[        UR                  S   5      5        SUR                  ;   a  [        USUR                  S   5        UR                  SS5      n[	        X4S[
        0UD6n[        U5        U(       ae  UR                  SS9  [        R                  R                  R                  U5      Ul        [        R                  R                  R                  USS9  Ub  UR                  UR                  USS	95        U(       a8  [        R                  R                  R!                  USS9  UR#                  5         U$ )
Nnum_classes
categoriesbackendqnnpackrp   T)r=   rA   )r   
check_hash)r   r   metapopr   rf   r   rC   rK   aoquantizationget_default_qat_qconfigrG   prepare_qatload_state_dictget_state_dictconverteval)r   r   r   r   r   r&   r   models           r3   _mobilenet_v3_modelr   }   s    fmSl9S5TU$!&)W\\)5LMjjI.G"#<xRmxqwxE%
 	%--EEgN))%)>g44hSW4XY%%eT%:

Lr5   c                   f    \ rS rSr\" S\" \SS9SS\SS\R                  S	S
SS.0SSSS.
S9r
\
rSrg)r       zUhttps://download.pytorch.org/models/quantized/mobilenet_v3_large_qnnpack-5bcacf28.pth   )	crop_sizeiS )r   r   r   zUhttps://github.com/pytorch/vision/tree/main/references/classification#qat-mobilenetv3zImageNet-1KgK7A@R@gxV@)zacc@1zacc@5g-?gҍ5@z
                These weights were produced by doing Quantization Aware Training (eager mode) on top of the unquantized
                weights listed below.
            )

num_paramsmin_sizer   r   recipeunquantized_metrics_ops
_file_size_docs)url
transformsr    N)r\   r]   r^   r_   r   r   r   r   r   IMAGENET1K_V1IMAGENET1K_QNNPACK_V1DEFAULTrb   r   r5   r3   r    r       s_    #c.#>!. m5CC##   
0 $Gr5   r    quantized_mobilenet_v3_large)name
pretrainedc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ )Nr   F)rI   r    r   r   r   )r&   s    r3   <lambda>r      s1    ::j%(( ;PP 6'556r5   )r   TF)r   r   r   c                 |    U(       a  [         O[        R                  U 5      n [        S0 UD6u  pE[	        XEXU40 UD6$ )ap  
MobileNetV3 (Large) model from
`Searching for MobileNetV3 <https://arxiv.org/abs/1905.02244>`_.

.. note::
    Note that ``quantize = True`` returns a quantized model with 8 bit
    weights. Quantized models only support inference and run on CPUs.
    GPU inference is not yet supported.

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

.. autoclass:: torchvision.models.quantization.MobileNet_V3_Large_QuantizedWeights
    :members:
.. autoclass:: torchvision.models.MobileNet_V3_Large_Weights
    :members:
    :noindex:
)r!   )r    r   verifyr   r   )r   r   r   r&   r   r   s         r3   r!   r!      sE    Z 7?2D^ffgnoG.@.`Y_.`+8[cngmnnr5   )-	functoolsr   typingr   r   r   r   rK   r   r	   torch.ao.quantizationr
   r   ops.miscr   r   transforms._presetsr   _apir   r   r   _metar   _utilsr   r   mobilenetv3r   r   r   r   r   utilsr   r   __all__r#   rf   r   intra   r   r    r!   r   r5   r3   <module>r      sN    - -   8 ? 6 7 7 ( C  02
#4 2
j
!"2 
!%[ %:!#$:;!! k"! 	!
 ! ! !H$+ $8 34	6 ae	'oe?A[[\]'o 'o 	'o
 'o 'o 5'or5   