
    ёiyU                    v   % S SK Jr  S SKJrJr  S SK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  \(       a<  S S	KJrJr  S S
KJrJr  S SKJr  S SKJr  \S   r\S   r " S S\5      r " S S\5      r/ rSSSSSSSS.rS\S'   S,S jrS-S jr " S S\R@                  5      r! " S  S!\R@                  5      r" " S" S#\R@                  5      r#  S.         S/S$ jjr$ S0     S1S% jjr% S0     S1S& jjr& S0     S1S' jjr' S0     S1S( jjr( S0     S1S) jjr) S0     S1S* jjr* S0     S2S+ jjr+g)3    )annotations)TYPE_CHECKINGCallableN)nn)AdaptiveAvgPool2DLinear	MaxPool2D)get_weights_path_from_url   )ConvNormActivation)Literal	TypedDict)NotRequiredUnpack)Tensor)Size2)shufflenet_v2_x0_25shufflenet_v2_x0_33shufflenet_v2_x0_5shufflenet_v2_x1_0shufflenet_v2_x1_5shufflenet_v2_x2_0shufflenet_v2_swish)reluswishc                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg	)
_ShuffleNetOptions.   z#NotRequired[_ActivationType | None]actNotRequired[bool]	with_poolNotRequired[int]num_classes N__name__
__module____qualname____firstlineno____annotations____static_attributes__r$       a/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/vision/models/shufflenetv2.pyr   r   .   s    00$$%%r,   r   c                  *    \ rS rSr% S\S'   S\S'   Srg)_ShuffleNetSwishOptions3   r    r!   r"   r#   r$   Nr%   r$   r,   r-   r/   r/   3   s    $$%%r,   r/   )zEhttps://paddle-hapi.bj.bcebos.com/models/shufflenet_v2_x0_25.pdparams 1e509b4c140eeb096bb16e214796d03b)zEhttps://paddle-hapi.bj.bcebos.com/models/shufflenet_v2_x0_33.pdparams 3d7b3ab0eaa5c0927ff1026d31b729bd)zDhttps://paddle-hapi.bj.bcebos.com/models/shufflenet_v2_x0_5.pdparams 5e5cee182a7793c4e4c73949b1a71bd4)zDhttps://paddle-hapi.bj.bcebos.com/models/shufflenet_v2_x1_0.pdparams 122d42478b9e81eb49f8a9ede327b1a4)zDhttps://paddle-hapi.bj.bcebos.com/models/shufflenet_v2_x1_5.pdparams faced5827380d73531d0ee027c67826d)zDhttps://paddle-hapi.bj.bcebos.com/models/shufflenet_v2_x2_0.pdparams cd3dddcd8305e7bcd8ad14d1c69a5784)zEhttps://paddle-hapi.bj.bcebos.com/models/shufflenet_v2_swish.pdparams adde0aa3b023e5b0c94a68be1c394b84zdict[str, tuple[str, str]]
model_urlsc                ~    U S:X  a  [         R                  $ U S:X  a  [         R                  $ U c  g [        SU  35      e)Nr   r   z*The activation function is not supported: )r   SwishReLURuntimeError)r   s    r-   create_activation_layerr=   Z   s=    
g~xx	ww	GuMNNr,   c                    U R                   SS u  p#pEX1-  n[        R                  " XXXE/S9n [        R                  " U / SQS9n [        R                  " XX4U/S9n U $ )Nr      )shape)r   r         r?   )perm)r@   paddlereshape	transpose)xgroups
batch_sizenum_channelsheightwidthchannels_per_groups          r-   channel_shufflerN   e   si    ./ggal+Jf%/ 		f&H	A
 	1A 	q\5 IJAHr,   c                  b   ^  \ rS rSr\R
                  4         SU 4S jjjrSS jrSrU =r	$ )InvertedResidualv   c           
        > [         TU ]  5         [        US-  US-  SSSSUS9U l        [        US-  US-  SUSUS-  S S9U l        [        US-  US-  SSSSUS9U l        g )Nr   rA   r   in_channelsout_channelskernel_sizestridepaddingrH   activation_layerrB   )super__init__r   _conv_pw_conv_dw_conv_linearselfrT   rU   rW   rY   	__class__s        r-   r[   InvertedResidual.__init__w   s     	*#q(%*-
 +$)%*1$!
 /$)%*-
r,   c                    [         R                  " UUR                  S   S-  UR                  S   S-  /SS9u  p#U R                  U5      nU R	                  U5      nU R                  U5      n[         R                  " X#/SS9n[        US5      $ )NrA   r   )num_or_sectionsaxisre   )rD   splitr@   r\   r]   r^   concatrN   r`   inputsx1x2outs        r-   forwardInvertedResidual.forward   s    #\\!_16<<?a3GH

 ]]2]]2r"mmRH1-sA&&r,   )r]   r^   r\   
rT   intrU   rq   rW   r   rY   zCallable[..., nn.Layer]returnNonerj   r   rr   r   
r&   r'   r(   r)   r   r;   r[   rn   r+   __classcell__ra   s   @r-   rP   rP   v   sQ     57GG"
"
 "
 	"

 2"
 
"
 "
H
' 
'r,   rP   c                  b   ^  \ rS rSr\R
                  4         SU 4S jjjrSS jrSrU =r	$ )InvertedResidualDS   c           
       > [         TU ]  5         [        UUSUSUS S9U l        [        UUS-  SSSSUS9U l        [        UUS-  SSSSUS9U l        [        US-  US-  SUSUS-  S S9U l        [        US-  US-  SSSSUS9U l        g )NrB   rA   rS   r   r   )rZ   r[   r   
_conv_dw_1_conv_linear_1
_conv_pw_2
_conv_dw_2_conv_linear_2r_   s        r-   r[   InvertedResidualDS.__init__   s     	 -#$!
 1#%*-
 -#%*-
 -$)%*1$!
 1$)%*-
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[
        R                  " X#/SS9n[        US5      $ )NrA   rf   r   )r|   r}   r~   r   r   rD   rh   rN   ri   s        r-   rn   InvertedResidualDS.forward   sk    __V$  $__V$__R   $mmRH1-sA&&r,   )r|   r   r}   r   r~   rp   rt   ru   rw   s   @r-   ry   ry      sQ     57GG7
7
 7
 	7

 27
 
7
 7
r' 'r,   ry   c                  x   ^  \ rS rSr% SrS\S'   S\S'   S\S'       S         SU 4S	 jjjrSS
 jrSrU =r	$ )ShuffleNetV2   a  ShuffleNetV2 model from
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    scale (float, optional): Scale of output channels. Default: True.
    act (str, optional): Activation function of neural network. Default: "relu".
    num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
                        will not be defined. Default: 1000.
    with_pool (bool, optional): Use pool before the last fc layer or not. Default: True.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 model.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import ShuffleNetV2

        >>> shufflenet_v2_swish = ShuffleNetV2(scale=1.0, act="swish")
        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = shufflenet_v2_swish(x)
        >>> print(out.shape)
        paddle.Size([1, 1000])
floatscalerq   r#   boolr!   c                  > [         TU ]  5         Xl        X0l        X@l        / SQn[        U5      nUS:X  a  / SQnOQUS:X  a  / SQnOFUS:X  a  / SQnO;US:X  a  / S	QnO0US
:X  a  / SQnO%US:X  a  / SQnO[        S[        U5      -   S-   5      e[        SUS   SSSUS9U l	        [        SSSS9U l        / U l        [        U5       H  u  p[        U	5       H  n
U
S:X  aC  U R                  [!        XxS-      XxS-      SUS9[        US-   5      S-   [        U
S-   5      -   S9nOBU R                  [#        XxS-      XxS-      SUS9[        US-   5      S-   [        U
S-   5      -   S9nU R                  R%                  U5        M     M     [        US   US   SSSUS9U l        U(       a  [)        S5      U l        US:  a  US   U l        [/        US   U5      U l        g g )N)r?      r?         ?)   r   0   `      Q?)r   r       @      r         ?)r   r   r   r               ?)r   r   t      i  r         ?)r   r      i`  i  r          @)r   r      i  i  i   zThis scale size:[z] is not implemented!rB   rA   r   )rT   rU   rV   rW   rX   rY   )rV   rW   rX   r   )rT   rU   rW   rY   _)sublayernamer   )rZ   r[   r   r#   r!   r=   NotImplementedErrorstrr   _conv1r	   	_max_pool_block_list	enumeraterangeadd_sublayerry   rP   append
_last_convr   _pool2d_avg_out_cr   _fc)r`   r   r   r#   r!   stage_repeatsrY   stage_out_channelsstage_id
num_repeatiblockra   s               r-   r[   ShuffleNetV2.__init__  s6    	
&"!237D=!:d]!;c\!<c\!>c\!>c\!>%#c%j03JJ  )+A.-
 #qAF $-m$< H:&6 --!3(:a<(H);qL)I#$-=	" !A.4s1q5zA . E !--!1(:a<(H);qL)I#$-=	" !A.4s1q5zA . E   ''.+ ' %=0 -*2.+B/-
 03D ?,R0DK04kBDH r,   c                T   U R                  U5      nU R                  U5      nU R                   H  nU" U5      nM     U R                  U5      nU R                  (       a  U R                  U5      nU R                  S:  a'  [        R                  " USSS9nU R                  U5      nU$ )Nr   rA   r   )
start_axis	stop_axis)
r   r   r   r   r!   r   r#   rD   flattenr   )r`   rj   rG   invs       r-   rn   ShuffleNetV2.forward`  s    KKNN1##CAA $OOA>>  #AaqQ"=AAr,   )
r   r   r   r   r   r   r   r#   r   r!   )r   r   i  T)
r   r   r   _ActivationType | Noner#   rq   r!   r   rr   rs   rt   )
r&   r'   r(   r)   __doc__r*   r[   rn   r+   rv   rw   s   @r-   r   r      s{    4 LO &,RCRC $RC 	RC
 RC 
RC RCh r,   r   c                    [        SSU0UD6nU(       a[  U [        ;   d
   U  S35       e[        [        U    S   [        U    S   5      n[        R                  " U5      nUR                  U5        U$ )Nr   zJ model do not have a pretrained model now, you should set pretrained=Falser   rA   r$   )r   r8   r
   rD   loadset_dict)arch
pretrainedr   kwargsmodelweight_pathparams          r-   _shufflenet_v2r   p  s     /u//Ez! 	
f^_	
! 0tQD!1!!4
 K(uLr,   c                     [         SSU S.UD6$ )a  ShuffleNetV2 with 0.25x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
                        on ImageNet. Default: False.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 <api_paddle_vision_models_ShuffleNetV2>`.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.25x output channels.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import shufflenet_v2_x0_25

        >>> # build model
        >>> model = shufflenet_v2_x0_25()

        >>> # build model and load imagenet pretrained weight
        >>> # model = shufflenet_v2_x0_25(pretrained=True)

        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = model(x)

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   r   r   )r   r   r   r   s     r-   r   r     '    @ %)jDJ r,   c                     [         SSU S.UD6$ )a  ShuffleNetV2 with 0.33x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
                        on ImageNet. Default: False.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 <api_paddle_vision_models_ShuffleNetV2>`.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.33x output channels.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import shufflenet_v2_x0_33

        >>> # build model
        >>> model = shufflenet_v2_x0_33()

        >>> # build model and load imagenet pretrained weight
        >>> # model = shufflenet_v2_x0_33(pretrained=True)

        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = model(x)

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   r   )r   r   r   s     r-   r   r     r   r,   c                     [         SSU S.UD6$ )a  ShuffleNetV2 with 0.5x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
                        on ImageNet. Default: False.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 <api_paddle_vision_models_ShuffleNetV2>`.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.5x output channels.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import shufflenet_v2_x0_5

        >>> # build model
        >>> model = shufflenet_v2_x0_5()

        >>> # build model and load imagenet pretrained weight
        >>> # model = shufflenet_v2_x0_5(pretrained=True)

        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = model(x)

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   r   )r   r   r   s     r-   r   r     '    @ $'JBH r,   c                     [         SSU S.UD6$ )a  ShuffleNetV2 with 1.0x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
                        on ImageNet. Default: False.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 <api_paddle_vision_models_ShuffleNetV2>`.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 1.0x output channels.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import shufflenet_v2_x1_0

        >>> # build model
        >>> model = shufflenet_v2_x1_0()

        >>> # build model and load imagenet pretrained weight
        >>> # model = shufflenet_v2_x1_0(pretrained=True)

        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = model(x)

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   r   )r   r   r   s     r-   r   r     r   r,   c                     [         SSU S.UD6$ )a  ShuffleNetV2 with 1.5x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
                        on ImageNet. Default: False.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 <api_paddle_vision_models_ShuffleNetV2>`.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 1.5x output channels.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import shufflenet_v2_x1_5

        >>> # build model
        >>> model = shufflenet_v2_x1_5()

        >>> # build model and load imagenet pretrained weight
        >>> # model = shufflenet_v2_x1_5(pretrained=True)

        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = model(x)

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   r   )r   r   r   s     r-   r   r     r   r,   c                     [         SSU S.UD6$ )a  ShuffleNetV2 with 2.0x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
                        on ImageNet. Default: False.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 <api_paddle_vision_models_ShuffleNetV2>`.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 2.0x output channels.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import shufflenet_v2_x2_0

        >>> # build model
        >>> model = shufflenet_v2_x2_0()

        >>> # build model and load imagenet pretrained weight
        >>> # model = shufflenet_v2_x2_0(pretrained=True)

        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = model(x)

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   r   )r   r   r   s     r-   r   r   =  r   r,   c                "    [         SSSU S.UD6$ )a  ShuffleNetV2 with swish activation function, as described in
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
                        on ImageNet. Default: False.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 <api_paddle_vision_models_ShuffleNetV2>`.

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with swish activation function.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import shufflenet_v2_swish

        >>> # build model
        >>> model = shufflenet_v2_swish()

        >>> # build model and load imagenet pretrained weight
        >>> # model = shufflenet_v2_swish(pretrained=True)

        >>> x = paddle.rand([1, 3, 224, 224])
        >>> out = model(x)

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   r   )r   r   r   )r   r   r   s     r-   r   r   b  s-    @ 	
  r,   )r   r   rr   znn.Layer | None)rG   r   rH   rq   rr   r   )Fr   )
r   _ShuffleNetArchr   r   r   r   r   Unpack[_ShuffleNetOptions]rr   r   )F)r   r   r   r   rr   r   )r   r   r   zUnpack[_ShuffleNetSwishOptions]rr   r   ),
__future__r   typingr   r   rD   r   	paddle.nnr   r   r	   paddle.utils.downloadr
   opsr   r   r   typing_extensionsr   r   r   paddle._typingr   r   _ActivationTyper   r/   __all__r8   r*   r=   rN   LayerrP   ry   r   r   r   r   r   r   r   r   r   r$   r,   r-   <module>r      s   # *   : : ; $)5$	O o.O&Y &
&) &
 3*
& @O"/'rxx /'dB' B'J@288 @J 
  )	
 * ""(B""L ""(B""L ""(B""L ""(B""L ""(B""L ""(B""L &&(G&&r,   