
    h($                        S SK Jr  S SK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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      c/var/www/auris/envauris/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)r0   r5   s     r2   forward$QuantizableSqueezeExcitation.forward&   s"    }}  U!3U;;r4   is_qatc                      [        U SS/USS9  g )Nfc1
activationTinplace)r   )r0   r<   s     r2   
fuse_model'QuantizableSqueezeExcitation.fuse_model)   s    dUL164Hr4   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)r0   
state_dictprefixlocal_metadatastrictmissing_keysunexpected_keys
error_msgsrE   default_state_dictkvfull_keyr1   s                r2   rN   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
 	%	
r4   )r.   r7   )__name__
__module____qualname____firstlineno___versionr   r+   r   r:   r   boolrB   rN   __static_attributes____classcell__r1   s   @r2   r"   r"      sY    H7c 7S 7T 7
<V < <I$ I4 I$
 $
r4   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_addr/   s      r2   r+   $QuantizableInvertedResidual.__init__U   s/    $P)EPP446r4   xc                     U R                   (       a*  U R                  R                  XR                  U5      5      $ U R                  U5      $ r7   )use_res_connectri   addblockr0   rk   s     r2   r:   #QuantizableInvertedResidual.forwardY   s6    ==$$Q

166::a= r4   )ri   )
r[   r\   r]   r^   r   r+   r   r:   ra   rb   rc   s   @r2   re   re   S   s5    7c 7S 7T 7! !F ! !r4   re   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	   dequantr/   s      r2   r+   QuantizableMobileNetV3.__init__a   s)     	$)&)[
"}r4   rk   c                 l    U R                  U5      nU R                  U5      nU R                  U5      nU$ r7   )ru   _forward_implrv   rp   s     r2   r:   QuantizableMobileNetV3.forwardl   s1    JJqMq!LLOr4   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   2Tr@   )
modulestyper   lenr   ReLUappendr   r"   rB   )r0   r<   mmodules_to_fuses       r2   rB   !QuantizableMobileNetV3.fuse_modelr   sy    AAw..#&*q6Q;4!:#8#**3/a&$Ga88V$  r4   )rv   ru   r7   )r[   r\   r]   r^   r   r+   r   r:   r   r`   rB   ra   rb   rc   s   @r2   r   r   `   sL    	%c 	%S 	%T 	% F %$ %4 % %r4   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qnnpackro   T)r<   r@   )r   
check_hash)r   r   metapopr   re   r   rB   rJ   aoquantizationget_default_qat_qconfigrF   prepare_qatload_state_dictget_state_dictconverteval)r   r   r   r   r   r%   r   models           r2   _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%:

Lr4   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DEFAULTra   r   r4   r2   r   r      s_    #c.#>!. m5CC##   
0 $Gr4   r   quantized_mobilenet_v3_large)name
pretrainedc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ )Nr   F)rH   r   r   r   r   )r%   s    r2   <lambda>r      s1    zz*e,, 0EE :+99:r4   )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         r2   r    r       sE    ^ 7?2D^ffgnoG.@.`Y_.`+8[cngmnnr4   )-	functoolsr   typingr   r   r   rJ   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"   re   r   listintr`   r   r   r    r   r4   r2   <module>r      sN    ' '   8 ? 6 7 7 ( C  02
#4 2
j
!"2 
!%[ %:!#$:;!! k"! 	!
 ! ! !H$+ $8 34	
	 ae	'oe?A[[\]'o 'o 	'o
 'o 'o	 5'or4   