
    hnB                     D   S SK Jr  S SKJrJrJr  S SKrS SKJr  S SK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  SSKJrJrJrJr  SSKJrJrJr  / SQr " S S\R@                  5      r! " S S\RD                  5      r#S\$\%   S\$\%   S\\   S\&S\&S\S\#4S jr'S\SSSS .r( " S! S"\5      r) " S# S$\5      r* " S% S&\5      r+ " S' S(\5      r,\" S)S*9\" S+S, 4S-9SS.S/S0.S\\\)\4      S\&S\&S\S\#4
S1 jj5       5       r-\" S2S*9\" S+S3 4S-9SS.S/S0.S\\\*\4      S\&S\&S\S\#4
S4 jj5       5       r.\" S5S*9\" S+S6 4S-9SS.S/S0.S\\\+\4      S\&S\&S\S\#4
S7 jj5       5       r/\" S8S*9\" S+S9 4S-9SS.S/S0.S\\\,\4      S\&S\&S\S\#4
S: jj5       5       r0g);    )partial)AnyOptionalUnionN)Tensor)shufflenetv2   )ImageClassification   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)ShuffleNet_V2_X0_5_WeightsShuffleNet_V2_X1_0_WeightsShuffleNet_V2_X1_5_WeightsShuffleNet_V2_X2_0_Weights   )_fuse_modules_replace_reluquantize_model)	QuantizableShuffleNetV2#ShuffleNet_V2_X0_5_QuantizedWeights#ShuffleNet_V2_X1_0_QuantizedWeights#ShuffleNet_V2_X1_5_QuantizedWeights#ShuffleNet_V2_X2_0_QuantizedWeightsshufflenet_v2_x0_5shufflenet_v2_x1_0shufflenet_v2_x1_5shufflenet_v2_x2_0c                   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	$ )
QuantizableInvertedResidual#   argskwargsreturnNc                 l   > [         TU ]  " U0 UD6  [        R                  R	                  5       U l        g N)super__init__nn	quantizedFloatFunctionalcatselfr&   r'   	__class__s      d/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/models/quantization/shufflenetv2.pyr,   $QuantizableInvertedResidual.__init__$   s)    $)&)<<//1    xc                 B   U R                   S:X  a=  UR                  SSS9u  p#U R                  R                  X R                  U5      /SS9nO:U R                  R                  U R	                  U5      U R                  U5      /SS9n[
        R                  " US5      nU$ )Nr   r   )dim)stridechunkr0   branch2branch1r   channel_shuffle)r2   r7   x1x2outs        r4   forward#QuantizableInvertedResidual.forward(   s    ;;!WWQAW&FB((,,LL$451,=C((,,QaAq,IC**32
r6   )r0   )
__name__
__module____qualname____firstlineno__r   r,   r   rB   __static_attributes____classcell__r3   s   @r4   r$   r$   #   s5    2c 2S 2T 2	 	F 	 	r6   r$   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   4   r&   r'   r(   Nc                    > [         TU ]  " US[        0UD6  [        R                  R
                  R                  5       U l        [        R                  R
                  R                  5       U l	        g )Ninverted_residual)
r+   r,   r$   torchaoquantization	QuantStubquantDeQuantStubdequantr1   s      r4   r,    QuantizableShuffleNetV2.__init__6   sP    $X2MXQWXXX**446
xx,,88:r6   r7   c                 l    U R                  U5      nU R                  U5      nU R                  U5      nU$ r*   )rS   _forward_implrU   )r2   r7   s     r4   rB   QuantizableShuffleNetV2.forward;   s1    JJqMq!LLOr6   is_qatc                    U R                   R                  5        H!  u  p#US;   d  M  Uc  M  [        U/ SQ/USS9  M#     U R                  5        H  n[	        U5      [
        L d  M  [        UR                  R                   R                  5       5      S:  a  [        UR                  SS// S	Q/USS9  [        UR                  / SQS
S// SQ/USS9  M     g)a  Fuse conv/bn/relu modules in shufflenetv2 model

Fuse conv+bn+relu/ conv+relu/conv+bn modules to prepare for quantization.
Model is modified in place.

.. note::
    Note that this operation does not change numerics
    and the model after modification is in floating point
)conv1conv5N)012T)inplacer   r^   r_   )r`   34rb   rc   )567)	_modulesitemsr   modulestyper$   lenr=   r<   )r2   rZ   namems       r4   
fuse_model"QuantizableShuffleNetV2.fuse_modelA   s     }}**,GD))ama/!2FDI - AAw55qyy))//12Q6!!))sCj/-JF\`aII$sCj/B 		  r6   )rU   rS   r*   )rD   rE   rF   rG   r   r,   r   rB   r   boolrn   rH   rI   rJ   s   @r4   r   r   4   sL    ;c ;S ;T ;
 F $ 4  r6   r   stages_repeatsstages_out_channels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0 UD6n[        U5        U(       a  [        Xv5        Ub  UR                  UR                  USS95        U$ )Nnum_classes
categoriesbackendfbgemmT)rt   
check_hash)	r   rk   metapopr   r   r   load_state_dictget_state_dict)rq   rr   rs   rt   ru   r'   ry   models           r4   _shufflenetv2r   Z   s     fmSl9S5TU$!&)W\\)5LMjjH-G#NR6RE%u&g44hSW4XYLr6   )r   r   rz   zdhttps://github.com/pytorch/vision/tree/main/references/classification#post-training-quantized-modelsz
        These weights were produced by doing Post Training Quantization (eager mode) on top of the unquantized
        weights listed below.
    )min_sizerx   ry   recipe_docsc                   d    \ rS rSr\" S\" \SS90 \ES\R                  SSSS	.0S
SS.ES9r
\
rSrg)r      zShttps://download.pytorch.org/models/quantized/shufflenetv2_x0.5_fbgemm-00845098.pth   	crop_sizei ImageNet-1Kg#~jL@gRS@zacc@1zacc@5g{Gz?gjt?
num_paramsunquantized_metrics_ops
_file_sizeurl
transformsr|    N)rD   rE   rF   rG   r   r   r
   _COMMON_METAr   IMAGENET1K_V1IMAGENET1K_FBGEMM_V1DEFAULTrH   r   r6   r4   r   r      s[    "a.#>

!5CC##  
" #Gr6   r   c                   d    \ rS rSr\" S\" \SS90 \ES\R                  SSSS	.0S
SS.ES9r
\
rSrg)r      zQhttps://download.pytorch.org/models/quantized/shufflenetv2_x1_fbgemm-1e62bb32.pthr   r   i" r   gףp=
Q@gh|?U@r   g(\?gy&1@r   r   r   N)rD   rE   rF   rG   r   r   r
   r   r   r   r   r   rH   r   r6   r4   r   r      s[    "_.#>

!5CC##  
" #Gr6   r   c                   h    \ rS rSr\" S\" \SSS90 \ESS\R                  SS	S
S.0SSS.ES9r
\
rSrg)r      zShttps://download.pytorch.org/models/quantized/shufflenetv2_x1_5_fbgemm-d7401f05.pthr      r   resize_size+https://github.com/pytorch/vision/pull/5906iv5 r   gSR@g̬V@r   gl?gK7A`@r   r   r   r   r   r   r   r   N)rD   rE   rF   rG   r   r   r
   r   r   r   r   r   rH   r   r6   r4   r   r      `    "a.#3O

C!5CC##  
$ #Gr6   r   c                   h    \ rS rSr\" S\" \SSS90 \ESS\R                  SS	S
S.0SSS.ES9r
\
rSrg)r      zShttps://download.pytorch.org/models/quantized/shufflenetv2_x2_0_fbgemm-5cac526c.pthr   r   r   r   ip r   g-R@gZd;W@r   g-?g|?5@r   r   r   N)rD   rE   rF   rG   r   r   r
   r   r   r   r   r   rH   r   r6   r4   r   r      r   r6   r   quantized_shufflenet_v2_x0_5)rl   
pretrainedc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ Nru   F)getr   r   r   r   r'   s    r4   <lambda>r      1    zz*e,, 0DD :+99:r6   )rs   TFrs   rt   ru   c                 n    U(       a  [         O[        R                  U 5      n [        / SQ/ SQ4XUS.UD6$ )a  
Constructs a ShuffleNetV2 with 0.5x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

.. 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.ShuffleNet_V2_X0_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X0_5_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model.
        Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X0_5_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ShuffleNet_V2_X0_5_Weights
    :members:
    :noindex:
      r   )   0   `   r      r   )r   r   verifyr   rs   rt   ru   r'   s       r4   r   r      sB    d 7?2D^ffgnoG*4;Yaek r6   quantized_shufflenet_v2_x1_0c                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r4   r   r     r   r6   c                 n    U(       a  [         O[        R                  U 5      n [        / SQ/ SQ4XUS.UD6$ )a  
Constructs a ShuffleNetV2 with 1.0x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

.. 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.ShuffleNet_V2_X1_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_0_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model.
        Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X1_0_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ShuffleNet_V2_X1_0_Weights
    :members:
    :noindex:
r   )r   t   r   i  r   r   )r   r   r   r   r   s       r4   r    r      B    d 7?2D^ffgnoG,6=[cgm r6   quantized_shufflenet_v2_x1_5c                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r4   r   r   J  r   r6   c                 n    U(       a  [         O[        R                  U 5      n [        / SQ/ SQ4XUS.UD6$ )a  
Constructs a ShuffleNetV2 with 1.5x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

.. 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.ShuffleNet_V2_X1_5_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X1_5_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model.
        Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X1_5_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ShuffleNet_V2_X1_5_Weights
    :members:
    :noindex:
r   )r      i`  i  r   r   )r   r   r   r   r   s       r4   r!   r!   F  r   r6   quantized_shufflenet_v2_x2_0c                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r4   r   r     r   r6   c                 n    U(       a  [         O[        R                  U 5      n [        / SQ/ SQ4XUS.UD6$ )a  
Constructs a ShuffleNetV2 with 2.0x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

.. 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.ShuffleNet_V2_X2_0_QuantizedWeights` or :class:`~torchvision.models.ShuffleNet_V2_X2_0_Weights`, optional): The
        pretrained weights for the model. See
        :class:`~torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights` 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.
    quantize (bool, optional): If True, return a quantized version of the model.
        Default is False.
    **kwargs: parameters passed to the ``torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.quantization.ShuffleNet_V2_X2_0_QuantizedWeights
    :members:

.. autoclass:: torchvision.models.ShuffleNet_V2_X2_0_Weights
    :members:
    :noindex:
r   )r      i  i  i   r   )r   r   r   r   r   s       r4   r"   r"   ~  r   r6   )1	functoolsr   typingr   r   r   rO   torch.nnr-   r   torchvision.modelsr   transforms._presetsr
   _apir   r   r   _metar   _utilsr   r   r   r   r   r   utilsr   r   r   __all__InvertedResidualr$   ShuffleNetV2r   listintrp   r   r   r   r   r   r   r   r    r!   r"   r   r6   r4   <module>r      s    ' '    + 6 7 7 ( C  @ ?
,"?"? "#l77 #LIc k"	
    6 &t	#+ #*#+ #*#+ #,#+ #, 34	
	 ae	*e?A[[\]* * 	*
 * *	 5*Z 34	
	 ae	*e?A[[\]* * 	*
 * *	 5*Z 34	
	 ae	*e?A[[\]* * 	*
 * *	 5*Z 34	
	 ae	*e?A[[\]* * 	*
 * *	 5*r6   