
    YhnB                        d dl mZ d dlmZmZmZ d dlZd dlmZ d dlm	Z	 d dl
mZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZmZ ddlmZmZmZmZ ddlmZmZmZ g dZ G d dej                   Z! G d dej"                  Z#de$e%         de$e%         dee         de&de&dede#fdZ'dedddd Z( G d! d"e          Z) G d# d$e          Z* G d% d&e          Z+ G d' d(e          Z, ed)*           ed+d, f-          dd.d/d0deee)ef                  de&de&dede#f
d1                        Z- ed2*           ed+d3 f-          dd.d/d0deee*ef                  de&de&dede#f
d4                        Z. ed5*           ed+d6 f-          dd.d/d0deee+ef                  de&de&dede#f
d7                        Z/ ed8*           ed+d9 f-          dd.d/d0deee,ef                  de&de&dede#f
d:                        Z0dS );    )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                   <     e Zd Zdededdf fdZdedefdZ xZS )QuantizableInvertedResidualargskwargsreturnNc                      t                      j        |i | t          j                                        | _        d S N)super__init__nn	quantizedFloatFunctionalcatselfr%   r&   	__class__s      ~/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torchvision/models/quantization/shufflenetv2.pyr+   z$QuantizableInvertedResidual.__init__$   s8    $)&)))<//11    xc                 f   | j         dk    rL|                    dd          \  }}| j                            ||                     |          gd          }nD| j                            |                     |          |                     |          gd          }t          j        |d          }|S )Nr   r   )dim)stridechunkr/   branch2branch1r   channel_shuffle)r1   r5   x1x2outs        r3   forwardz#QuantizableInvertedResidual.forward(   s    ;!WWQAW&&FB(,,DLL$4$451,==CC(,,QaAq,IIC*322
r4   )__name__
__module____qualname__r   r+   r   r@   __classcell__r2   s   @r3   r$   r$   #   st        2c 2S 2T 2 2 2 2 2 2	 	F 	 	 	 	 	 	 	 	r4   r$   c                   Z     e Zd Zdededdf fdZdedefdZd
dee         ddfd	Z	 xZ
S )r   r%   r&   r'   Nc                      t                      j        |dt          i| t          j        j                                        | _        t          j        j                                        | _	        d S )Ninverted_residual)
r*   r+   r$   torchaoquantization	QuantStubquantDeQuantStubdequantr0   s      r3   r+   z QuantizableShuffleNetV2.__init__6   sZ    $X2MXQWXXXX*4466
x,88::r4   r5   c                     |                      |          }|                     |          }|                     |          }|S r)   )rM   _forward_implrO   )r1   r5   s     r3   r@   zQuantizableShuffleNetV2.forward;   s8    JJqMMq!!LLOOr4   is_qatc                    | j                                         D ]!\  }}|dv r|t          |g dg|d           "|                                 D ]}t	          |          t
          u rnt          |j        j                                                   dk    rt          |j        ddgg d	g|d           t          |j        g dd
dgg dg|d           dS )aB  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   rV   rW   )rX   34rZ   r[   )567)	_modulesitemsr   modulestyper$   lenr;   r:   )r1   rR   namems       r3   
fuse_modelz"QuantizableShuffleNetV2.fuse_modelA   s    }**,, 	J 	JGD!)))ama///!2FDIIII 		 		AAww555qy)//1122Q66!!)sCj///-JF\`aaaaI$__sCj///B 	   			 		r4   r)   )rA   rB   rC   r   r+   r   r@   r   boolrf   rD   rE   s   @r3   r   r   4   s        ;c ;S ;T ; ; ; ; ; ;
 F     $ 4        r4   r   stages_repeatsstages_out_channelsweightsprogressquantizer&   r'   c                   |Nt          |dt          |j        d                              d|j        v rt          |d|j        d                    |                    dd          }t	          | |fi |}t          |           |rt          ||           |*|                    |                    |d                     |S )Nnum_classes
categoriesbackendfbgemmT)rk   
check_hash)	r   rc   metapopr   r   r   load_state_dictget_state_dict)rh   ri   rj   rk   rl   r&   rp   models           r3   _shufflenetv2rx   Z   s     fmSl9S5T5TUUU$$!&)W\)5LMMMjjH--G#N4GRR6RRE% 'ug&&&g44hSW4XXYYYLr4   )r   r   rq   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_sizero   rp   recipe_docsc                   l    e Zd Z ed eed          i edej        ddddid	d
d          Z	e	Z
dS )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
transformsrs   N)rA   rB   rC   r   r   r
   _COMMON_METAr   IMAGENET1K_V1IMAGENET1K_FBGEMM_V1DEFAULT r4   r3   r   r      s        "7a7.#>>>

!5C##    
 
 
  " #GGGr4   r   c                   l    e Zd Z ed eed          i edej        ddddid	d
d          Z	e	Z
dS )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   N)rA   rB   rC   r   r   r
   r   r   r   r   r   r   r4   r3   r   r      s        "7_7.#>>>

!5C##    
 
 
  " #GGGr4   r   c                   p    e Zd Z ed eedd          i eddej        ddd	d
iddd          Z	e	Z
dS )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`@rz   r   r   r   r   r   r   N)rA   rB   rC   r   r   r
   r   r   r   r   r   r   r4   r3   r   r              "7a7.#3OOO

C!5C##    
 
 
  $ #GGGr4   r   c                   p    e Zd Z ed eedd          i eddej        ddd	d
iddd          Z	e	Z
dS )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   N)rA   rB   rC   r   r   r
   r   r   r   r   r   r   r4   r3   r   r      r   r4   r   quantized_shufflenet_v2_x0_5)rd   
pretrainedc                 ^    |                      dd          rt          j        nt          j        S Nrl   F)getr   r   r   r   r&   s    r3   <lambda>r      ,    zz*e,,:/DD+9 r4   )rj   TFrj   rk   rl   c                 t    |rt           nt                              |           } t          g dg df| ||d|S )aQ  
    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   verifyrx   rj   rk   rl   r&   s       r3   r   r      sa    d 7?^22D^ffgnooG		***4;hYa ek  r4   quantized_shufflenet_v2_x1_0c                 ^    |                      dd          rt          j        nt          j        S r   )r   r   r   r   r   r   s    r3   r   r     r   r4   c                 t    |rt           nt                              |           } t          g dg df| ||d|S )aQ  
    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   rx   r   s       r3   r    r      a    d 7?^22D^ffgnooG		,,,6=[c gm  r4   quantized_shufflenet_v2_x1_5c                 ^    |                      dd          rt          j        nt          j        S r   )r   r   r   r   r   r   s    r3   r   r   J  r   r4   c                 t    |rt           nt                              |           } t          g dg df| ||d|S )aQ  
    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   rx   r   s       r3   r!   r!   F  r   r4   quantized_shufflenet_v2_x2_0c                 ^    |                      dd          rt          j        nt          j        S r   )r   r   r   r   r   r   s    r3   r   r     r   r4   c                 t    |rt           nt                              |           } t          g dg df| ||d|S )aQ  
    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   rx   r   s       r3   r"   r"   ~  r   r4   )1	functoolsr   typingr   r   r   rI   torch.nnr,   r   torchvision.modelsr   transforms._presetsr
   _apir   r   r   _metar   _utilsr   r   r   r   r   r   utilsr   r   r   __all__InvertedResidualr$   ShuffleNetV2r   listintrg   rx   r   r   r   r   r   r   r    r!   r"   r   r4   r3   <module>r      s         ' ' ' ' ' ' ' ' ' '              + + + + + + 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 ( ( ( ( ( ( C C C C C C C C            @ ? ? ? ? ? ? ? ? ?
 
 
    ,"?   "# # # # #l7 # # #LIc k"	
       6 &t	 	# # # # #+ # # #*# # # # #+ # # #*# # # # #+ # # #,# # # # #+ # # #, 3444	
 	
	 	 	 ae	* * *e?A[[\]* * 	*
 * * * *	 	 54*Z 3444	
 	
	 	 	 ae	* * *e?A[[\]* * 	*
 * * * *	 	 54*Z 3444	
 	
	 	 	 ae	* * *e?A[[\]* * 	*
 * * * *	 	 54*Z 3444	
 	
	 	 	 ae	* * *e?A[[\]* * 	*
 * * * *	 	 54* * *r4   