
    ёiZ                    :   S SK Jr  S SKJrJrJr  S SK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  \(       a  S SK	Jr   " S S\5      r/ rSS0r " S S\
R*                  5      r " S S\
R*                  5      r S       SS jjr  S       SS jjrg)    )annotations)TYPE_CHECKINGCallable	TypedDict)NotRequiredUnpackN)nn)get_weights_path_from_url   )ConvNormActivation   )_make_divisible)Tensorc                  *    \ rS rSr% S\S'   S\S'   Srg)_MobileNetV2Options#   zNotRequired[int]num_classeszNotRequired[bool]	with_pool N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r       `/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/vision/models/mobilenetv2.pyr   r   #   s    %%$$r   r   zmobilenetv2_1.0)zChttps://paddle-hapi.bj.bcebos.com/models/mobilenet_v2_x1.0.pdparams 0340af0a901346c8d46f4529882fb63dc                  f   ^  \ rS rSr\R
                  4           SU 4S jjjrSS jrSrU =r	$ )InvertedResidual2   c                  > [         TU ]  5         X0l        US;   d   e[        [	        X-  5      5      nU R                  S:H  =(       a    X:H  U l        / nUS:w  a*  UR                  [        UUSU[        R                  S95        UR                  [        UUUUU[        R                  S9[        R                  " XbSSSSS9U" U5      /5        [        R                  " U6 U l        g )N)r   r   r   kernel_size
norm_layeractivation_layer)stridegroupsr%   r&   r   F)	bias_attr)super__init__r'   introunduse_res_connectappendr   r	   ReLU6extendConv2D
Sequentialconv)	selfinpoupr'   expand_ratior%   
hidden_dimlayers	__class__s	           r   r+   InvertedResidual.__init__3   s     	s123
#{{a/>CJ1MM" !)%'XX 	"!%)%'XX 		*1aeD3	
 MM6*	r   c                l    U R                   (       a  XR                  U5      -   $ U R                  U5      $ )N)r.   r4   r5   xs     r   forwardInvertedResidual.forward]   s*    yy|##99Q<r   )r4   r'   r.   )r6   r,   r7   r,   r'   r,   r8   floatr%   zCallable[..., nn.Layer]returnNoner?   r   rC   r   )
r   r   r   r   r	   BatchNorm2Dr+   r@   r   __classcell__r;   s   @r   r    r    2   s[     /1nn(+(+ (+ 	(+
 (+ ,(+ 
(+ (+T   r   r    c                  h   ^  \ rS rSr% SrS\S'   S\S'      S
       SU 4S jjjrSS jrS	rU =r	$ )MobileNetV2d   a  MobileNetV2 model from
`"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_.

Args:
    scale (float, optional): Scale of channels in each layer. Default: 1.0.
    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 MobileNetV2 model.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import MobileNetV2

        >>> model = MobileNetV2()

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
r,   r   boolr   c                n  > [         TU ]  5         X l        X0l        SnSn[        nSn[
        R                  n/ SQ/ SQ/ SQ/ SQ/ SQ/ S	Q/ S
Q/n	[        XA-  U5      n[        U[        SU5      -  U5      U l	        [        SUSU[
        R                  S9/n
U	 HK  u  pp[        X-  U5      n[        U5       H(  nUS:X  a  UOSnU
R                  U" UUUUUS95        UnM*     MM     U
R                  [        UU R                  SU[
        R                  S95        [
        R                  " U
6 U l        U(       a  [
        R                   " S5      U l        U R                  S:  aP  [
        R                  " [
        R$                  " S5      [
        R&                  " U R                  U5      5      U l        g g )N    i      )r      r   r   )      r   r   )rQ   rN      r   )rQ   @      r   )rQ   `   rS   r   )rQ      rS   r   )rQ   i@  r   r         ?rS   r   )r'   r%   r&   r   r   )r8   r%   r#   g?)r*   r+   r   r   r    r	   rF   r   maxlast_channelr   r0   ranger/   r3   featuresAdaptiveAvgPool2D
pool2d_avgDropoutLinear
classifier)r5   scaler   r   input_channelrZ   blockround_nearestr%   inverted_residual_settingr\   tcnsoutput_channelir'   r;   s                     r   r+   MobileNetV2.__init__   s    	&" ^^
%
! ((=}M+3sE?*M
 %!#
 4JA!,QYFN1X1f!%&%&#- !/  4 	!!%!#	
 x0 2215DOa mm

34+<+<k!JDO  r   c                    U R                  U5      nU R                  (       a  U R                  U5      nU R                  S:  a(  [        R
                  " US5      nU R                  U5      nU$ )Nr   r   )r\   r   r^   r   paddleflattenra   r>   s     r   r@   MobileNetV2.forward   sV    MM!>>"Aaq!$A"Ar   )ra   r\   rZ   r   r^   r   )rX   i  T)rb   rB   r   r,   r   rL   rC   rD   rE   )
r   r   r   r   __doc__r   r+   r@   r   rG   rH   s   @r   rJ   rJ   d   sa    6 O 	HH H 	H
 
H HT	 	r   rJ   c                    [        S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$ )NzJ model do not have a pretrained model now, you should set pretrained=Falser   r   r   )rJ   
model_urlsr
   ro   load	load_dict)arch
pretrainedkwargsmodelweight_pathparams         r   
_mobilenetr}      sz     !&!Ez! 	
f^_	
! 0tQD!1!!4
 K(Lr   c                <    [        S[        U5      -   U 4SU0UD6nU$ )a6  MobileNetV2 from
`"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_.

Args:
    pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False.
    scale (float, optional): Scale of channels in each layer. Default: 1.0.
    **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV2 <api_paddle_vision_models_MobileNetV2>`.

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

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import mobilenet_v2

        >>> # Build model
        >>> model = mobilenet_v2()

        >>> # Build model and load imagenet pretrained weight
        >>> # model = mobilenet_v2(pretrained=True)

        >>> # Build mobilenet v2 with scale=0.5
        >>> model = mobilenet_v2(scale=0.5)

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
mobilenetv2_rb   )r}   str)rx   rb   ry   rz   s       r   mobilenet_v2r      s4    J U#Z7<@FE Lr   )F)rw   r   rx   rL   ry   Unpack[_MobileNetV2Options]rC   rJ   )FrX   )rx   rL   rb   rB   ry   r   rC   rJ   )
__future__r   typingr   r   r   typing_extensionsr   r   ro   r	   paddle.utils.downloadr
   opsr   _utilsr   r   r   __all__rt   Layerr    rJ   r}   r   r   r   r   <module>r      s    #  2   ; $ #%i %
   
/ rxx / dr"(( rl #(
3N& ((( *( 	(r   