
    QЦiA                     H   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	  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\RB                  5      r" " S S\RF                  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List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      k/var/www/html/ai-image-ml/venv/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chunkr1   branch2branch1r	   channel_shuffle)r3   r8   x1x2outs        r5   forward#QuantizableInvertedResidual.forward(   s    ;;!WWQAW&FB((,,LL$451,=C((,,QaAq,IC**32
r7   )r1   )
__name__
__module____qualname____firstlineno__r   r-   r   rC   __static_attributes____classcell__r4   s   @r5   r%   r%   #   s5    2c 2S 2T 2	 	F 	 	r7   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dequantr2   s      r5   r-    QuantizableShuffleNetV2.__init__6   sP    $X2MXQWXXX**446
xx,,88:r7   r8   c                 l    U R                  U5      nU R                  U5      nU R                  U5      nU$ r+   )rT   _forward_implrV   )r3   r8   s     r5   rC   QuantizableShuffleNetV2.forward;   s1    JJqMq!LLOr7   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`   )ra   34rc   rd   )567)	_modulesitemsr   modulestyper%   lenr>   r=   )r3   r[   namems       r5   
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 		  r7   )rV   rT   r+   )rE   rF   rG   rH   r   r-   r   rC   r   boolro   rI   rJ   rK   s   @r5   r   r   4   sL    ;c ;S ;T ;
 F $ 4  r7   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)ru   
check_hash)	r   rl   metapopr   r   r   load_state_dictget_state_dict)rr   rs   rt   ru   rv   r(   rz   models           r5   _shufflenetv2r   Z   s     fmSl9S5TU$!&)W\\)5LMjjH-G#NR6RE%u&g44hSW4XYLr7   )r   r   r{   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_sizery   rz   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)rE   rF   rG   rH   r   r   r   _COMMON_METAr   IMAGENET1K_V1IMAGENET1K_FBGEMM_V1DEFAULTrI   r   r7   r5   r   r      s[    "a.#>

!5CC##  
" #Gr7   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)rE   rF   rG   rH   r   r   r   r   r   r   r   r   rI   r   r7   r5   r   r      s[    "_.#>

!5CC##  
" #Gr7   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)rE   rF   rG   rH   r   r   r   r   r   r   r   r   rI   r   r7   r5   r   r      `    "a.#3O

C!5CC##  
$ #Gr7   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)rE   rF   rG   rH   r   r   r   r   r   r   r   r   rI   r   r7   r5   r   r      r   r7   r   quantized_shufflenet_v2_x0_5)rm   
pretrainedc                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ Nrv   F)getr   r   r   r   r(   s    r5   <lambda>r      1    ::j%(( ;OO 6'556r7   )rt   TFrt   ru   rv   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   rt   ru   rv   r(   s       r5   r    r       sB    ` 7?2D^ffgnoG*4;Yaek r7   quantized_shufflenet_v2_x1_0c                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r5   r   r     r   r7   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       r5   r!   r!     B    ` 7?2D^ffgnoG,6=[cgm r7   quantized_shufflenet_v2_x1_5c                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r5   r   r   F  r   r7   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       r5   r"   r"   B  r   r7   quantized_shufflenet_v2_x2_0c                 p    U R                  SS5      (       a  [        R                  $ [        R                  $ r   )r   r   r   r   r   r   s    r5   r   r   |  r   r7   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       r5   r#   r#   x  r   r7   )1	functoolsr   typingr   r   r   r   rP   torch.nnr.   r   torchvision.modelsr	   transforms._presetsr   _apir   r   r   _metar   _utilsr   r   r   r   r   r   utilsr   r   r   __all__InvertedResidualr%   ShuffleNetV2r   intrq   r   r   r   r   r   r   r    r!   r"   r#   r   r7   r5   <module>r      s    - -    + 6 7 7 ( C  @ ?
,"?"? "#l77 #LIc k"	
    6 &t	#+ #*#+ #*#+ #,#+ #, 34	6 ae	*e?A[[\]* * 	*
 * * 5*Z 34	6 ae	*e?A[[\]* * 	*
 * * 5*Z 34	6 ae	*e?A[[\]* * 	*
 * * 5*Z 34	6 ae	*e?A[[\]* * 	*
 * * 5*r7   