
    hN<                     &   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QrS\	S\S\	4S jr " S S\R4                  5      r " S S\R4                  5      rS\\   S\S\S\S\4
S jrS\SS.r " S S\5      r  " S S \5      r! " S! S"\5      r" " S# S$\5      r#\" 5       \" S%\ RH                  4S&9SS'S(.S\\    S\S\S\4S) jj5       5       r%\" 5       \" S%\!RH                  4S&9SS'S(.S\\!   S\S\S\4S* jj5       5       r&\" 5       \" S%\"RH                  4S&9SS'S(.S\\"   S\S\S\4S+ jj5       5       r'\" 5       \" S%\#RH                  4S&9SS'S(.S\\#   S\S\S\4S, jj5       5       r(g)-    )partial)AnyCallableOptionalN)Tensor   )ImageClassification)_log_api_usage_once   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)	ShuffleNetV2ShuffleNet_V2_X0_5_WeightsShuffleNet_V2_X1_0_WeightsShuffleNet_V2_X1_5_WeightsShuffleNet_V2_X2_0_Weightsshufflenet_v2_x0_5shufflenet_v2_x1_0shufflenet_v2_x1_5shufflenet_v2_x2_0xgroupsreturnc                     U R                  5       u  p#pEX1-  nU R                  X!XdU5      n [        R                  " U SS5      R	                  5       n U R                  X#XE5      n U $ )Nr   r   )sizeviewtorch	transpose
contiguous)r   r   	batchsizenum_channelsheightwidthchannels_per_groups          W/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/models/shufflenetv2.pychannel_shuffler*      sb    -.VVX*IV%/ 	
y"4eDA1a ++-A 	
y6AH    c                      ^  \ rS rSrS\S\S\SS4U 4S jjr\ SS\S	\S
\S\S\S\S\R                  4S jj5       r
S\S\4S jrSrU =r$ )InvertedResidual+   inpoupstrider   Nc                   > [         TU ]  5         SUs=::  a  S::  d  O  [        S5      eX0l        US-  nU R                  S:X  a  XS-  :w  a  [        SU SU SU S35      eU R                  S:  a  [        R
                  " U R                  XSU R                  SS	9[        R                  " U5      [        R                  " XSSS
SS9[        R                  " U5      [        R                  " SS95      U l
        O[        R
                  " 5       U l
        [        R
                  " [        R                  " U R                  S:  a  UOUUSSS
SS9[        R                  " U5      [        R                  " SS9U R                  XDSU R                  SS	9[        R                  " U5      [        R                  " XDSSS
SS9[        R                  " U5      [        R                  " SS95      U l        g )Nr      zillegal stride valuer   zInvalid combination of stride z, inp z	 and oup zB values. If stride == 1 then inp should be equal to oup // 2 << 1.kernel_sizer1   paddingr   F)r5   r1   r6   biasTinplace)super__init__
ValueErrorr1   nn
Sequentialdepthwise_convBatchNorm2dConv2dReLUbranch1branch2)selfr/   r0   r1   branch_features	__class__s        r)   r;   InvertedResidual.__init__,   s   V q 344(KK13Q*>#>0se9SE  RT  U  ;;?==##C!DKKYZ#[s#		#AaQRY^_/%DL ==?DL}}IIao NN?+GGD!aX\XcXcmnoNN?+IIoAaYZafgNN?+GGD!
r+   ior5   r6   r7   c           
      0    [         R                  " XX#XEU S9$ )N)r7   r   )r=   rA   )rI   rJ   r5   r1   r6   r7   s         r)   r?   InvertedResidual.depthwise_convV   s     yy{GqQQr+   r   c                    U R                   S:X  a8  UR                  SSS9u  p#[        R                  " X R	                  U5      4SS9nO5[        R                  " U R                  U5      U R	                  U5      4SS9n[        US5      nU$ )Nr   r   )dim)r1   chunkr!   catrD   rC   r*   )rE   r   x1x2outs        r)   forwardInvertedResidual.forward\   st    ;;!WWQAW&FB))Rb!12:C))T\\!_dll1o>AFCc1%
r+   )rC   rD   r1   )r   r   F)__name__
__module____qualname____firstlineno__intr;   staticmethodboolr=   rA   r?   r   rT   __static_attributes____classcell__rG   s   @r)   r-   r-   +   s    (
C (
c (
3 (
4 (
T Z_RRR%(R25RDGRSWR	R R
	 	F 	 	r+   r-   c                      ^  \ rS rSrS\4S\\   S\\   S\S\S\R                  4   SS	4
U 4S
 jjjr
S\S\4S jrS\S\4S jrSrU =r$ )r   h   i  stages_repeatsstages_out_channelsnum_classesinverted_residual.r   Nc                   > [         TU ]  5         [        U 5        [        U5      S:w  a  [	        S5      e[        U5      S:w  a  [	        S5      eX l        SnU R
                  S   n[        R                  " [        R                  " XVSSSSS	9[        R                  " U5      [        R                  " S
S95      U l        Un[        R                  " SSSS9U l        U   U   U   S Vs/ s H  nSU 3PM
     nn[        XU R
                  SS  5       H\  u  pnU" XVS5      /n[        U
S-
  5       H  nUR!                  U" XfS5      5        M     [#        X	[        R                  " U6 5        UnM^     U R
                  S   n[        R                  " [        R                  " XVSSSSS	9[        R                  " U5      [        R                  " S
S95      U l        [        R&                  " Xc5      U l        g s  snf )Nr3   z2expected stages_repeats as list of 3 positive ints   z7expected stages_out_channels as list of 5 positive intsr   r   r   F)r7   Tr8   r4   )r   r3      stage)r:   r;   r
   lenr<   _stage_out_channelsr=   r>   rA   r@   rB   conv1	MaxPool2dmaxpoolziprangeappendsetattrconv5Linearfc)rE   rb   rc   rd   re   input_channelsoutput_channelsrI   stage_namesnamerepeatsseqrG   s               r)   r;   ShuffleNetV2.__init__i   s    	D!~!#QRR"#q(VWW#6 2215]]IInq!QUKNN?+GGD!


 )||!QG 	,56Iqqc{I6.1+tOgOghihjOk.l*D?$^aHIC7Q;'

,_qQR (Ds 34,N /m 2226]]IInq!QUKNN?+GGD!

 ))O9 7s   &G4r   c                    U R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU R	                  U5      nU R                  U5      nUR                  SS/5      nU R                  U5      nU$ )Nr   r3   )rm   ro   stage2stage3stage4rt   meanrv   rE   r   s     r)   _forward_implShuffleNetV2._forward_impl   ss    JJqMLLOKKNKKNKKNJJqMFFAq6NGGAJr+   c                 $    U R                  U5      $ )N)r   r   s     r)   rT   ShuffleNetV2.forward   s    !!!$$r+   )rl   rm   rt   rv   ro   )rV   rW   rX   rY   r-   listrZ   r   r=   Moduler;   r   r   rT   r]   r^   r_   s   @r)   r   r   h   s    
  6F.:S	.: "#Y.: 	.:
 $CN3.: 
.: .:`
v 
& 
% %F % %r+   r   weightsprogressargskwargsc                     U b#  [        US[        U R                  S   5      5        [        U0 UD6nU b  UR	                  U R                  USS95        U$ )Nrd   
categoriesT)r   
check_hash)r   rk   metar   load_state_dictget_state_dict)r   r   r   r   models        r)   _shufflenetv2r      s]     fmSl9S5TU$)&)Eg44hSW4XYLr+   )r   r   z2https://github.com/ericsun99/Shufflenet-v2-Pytorch)min_sizer   recipec                   P    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SSS.ES9r\r	Sr
g)r      zDhttps://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth   	crop_sizei ImageNet-1Kg-FN@g9voT@zacc@1zacc@5g{Gz?gT㥛 @VThese weights were trained from scratch to reproduce closely the results of the paper.
num_params_metrics_ops
_file_size_docsurl
transformsr    NrV   rW   rX   rY   r   r   r	   _COMMON_METAIMAGENET1K_V1DEFAULTr]   r   r+   r)   r   r      sT    R.#>

!##  q
	M$ Gr+   r   c                   P    \ rS rSr\" S\" \SS90 \ESSSSS	.0S
SSS.ES9r\r	Sr
g)r      zBhttps://download.pytorch.org/models/shufflenetv2_x1-5666bf0f80.pthr   r   i" r   gI+WQ@gNbX9V@r   g(\?gE!@r   r   r   r   Nr   r   r+   r)   r   r      sT    P.#>

!##  q
	M$ Gr+   r   c                   T    \ rS rSr\" S\" \SSS90 \ESSSS	S
S.0SSSS.ES9r\r	Sr
g)r      zBhttps://download.pytorch.org/models/shufflenetv2_x1_5-3c479a10.pthr      r   resize_size+https://github.com/pytorch/vision/pull/5906iv5 r   g9v?R@g/$V@r   gl?gw/+@
                These weights were trained from scratch by using TorchVision's `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            r   r   r   r   r   r   r   r   Nr   r   r+   r)   r   r      [    P.#3O

C!##   
M* Gr+   r   c                   T    \ rS rSr\" S\" \SSS90 \ESSSS	S
S.0SSSS.ES9r\r	Sr
g)r   i  zBhttps://download.pytorch.org/models/shufflenetv2_x2_0-8be3c8ee.pthr   r   r   r   ip r   gQS@gMb@W@r   g-?g+n<@r   r   r   r   Nr   r   r+   r)   r   r     r   r+   r   
pretrained)r   T)r   r   c                 P    [         R                  U 5      n [        X/ SQ/ SQ40 UD6$ )a  
Constructs a ShuffleNetV2 architecture with 0.5x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

Args:
    weights (:class:`~torchvision.models.ShuffleNet_V2_X0_5_Weights`, optional): The
        pretrained weights to use. See
        :class:`~torchvision.models.ShuffleNet_V2_X0_5_Weights` 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.
    **kwargs: parameters passed to the ``torchvision.models.shufflenetv2.ShuffleNetV2``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.ShuffleNet_V2_X0_5_Weights
    :members:
rh      rh   )   0   `         )r   verifyr   r   r   r   s      r)   r   r     s*    4 )//8GI7NYRXYYr+   c                 P    [         R                  U 5      n [        X/ SQ/ SQ40 UD6$ )a  
Constructs a ShuffleNetV2 architecture with 1.0x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

Args:
    weights (:class:`~torchvision.models.ShuffleNet_V2_X1_0_Weights`, optional): The
        pretrained weights to use. See
        :class:`~torchvision.models.ShuffleNet_V2_X1_0_Weights` 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.
    **kwargs: parameters passed to the ``torchvision.models.shufflenetv2.ShuffleNetV2``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.ShuffleNet_V2_X1_0_Weights
    :members:
r   )r   t   r   i  r   )r   r   r   r   s      r)   r   r   >  *    4 )//8GI7P[TZ[[r+   c                 P    [         R                  U 5      n [        X/ SQ/ SQ40 UD6$ )a  
Constructs a ShuffleNetV2 architecture with 1.5x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

Args:
    weights (:class:`~torchvision.models.ShuffleNet_V2_X1_5_Weights`, optional): The
        pretrained weights to use. See
        :class:`~torchvision.models.ShuffleNet_V2_X1_5_Weights` 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.
    **kwargs: parameters passed to the ``torchvision.models.shufflenetv2.ShuffleNetV2``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.ShuffleNet_V2_X1_5_Weights
    :members:
r   )r      i`  i  r   )r   r   r   r   s      r)   r   r   ]  r   r+   c                 P    [         R                  U 5      n [        X/ SQ/ SQ40 UD6$ )a  
Constructs a ShuffleNetV2 architecture with 2.0x output channels, as described in
`ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design
<https://arxiv.org/abs/1807.11164>`__.

Args:
    weights (:class:`~torchvision.models.ShuffleNet_V2_X2_0_Weights`, optional): The
        pretrained weights to use. See
        :class:`~torchvision.models.ShuffleNet_V2_X2_0_Weights` 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.
    **kwargs: parameters passed to the ``torchvision.models.shufflenetv2.ShuffleNetV2``
        base class. Please refer to the `source code
        <https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py>`_
        for more details about this class.

.. autoclass:: torchvision.models.ShuffleNet_V2_X2_0_Weights
    :members:
r   )r      i  i  i   )r   r   r   r   s      r)   r   r   |  r   r+   ))	functoolsr   typingr   r   r   r!   torch.nnr=   r   transforms._presetsr	   utilsr
   _apir   r   r   _metar   _utilsr   r   __all__rZ   r*   r   r-   r   r\   r   r   r   r   r   r   r   r   r   r   r   r   r+   r)   <module>r      sn    * *    5 ' 6 6 ' B
v s v :ryy :z>%299 >%Bk"  	
 $ &B , , 2 2 ,0J0X0X!YZ7;dZ34ZGKZ^aZZ [ Z: ,0J0X0X!YZ7;d\34\GK\^a\\ [ \: ,0J0X0X!YZ7;d\34\GK\^a\\ [ \: ,0J0X0X!YZ7;d\34\GK\^a\\ [ \r+   