
    ёi$                    6   S SK Jr  S SK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  \(       a  S S	KJr  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	TypedDict)NotRequiredUnpackN)nn)get_weights_path_from_url   )ConvNormActivation)Tensor)Size2c                  *    \ rS rSr% S\S'   S\S'   Srg)_MobileNetV1Options"   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/mobilenetv1.pyr   r   "   s    %%$$r   r   zmobilenetv1_1.0)zAhttps://paddle-hapi.bj.bcebos.com/models/mobilenetv1_1.0.pdparams 3033ab1975b1670bef51545feb65fc45c                  R   ^  \ rS rSr              SU 4S jjrSS jrSrU =r$ )DepthwiseSeparable2   c                   > [         TU ]  5         [        U[        X&-  5      SUS[        XF-  5      S9U l        [        [        X&-  5      [        X6-  5      SSSS9U l        g )N      )kernel_sizestridepaddinggroupsr   )r#   r$   r%   )super__init__r   int_depthwise_conv_pointwise_conv)selfin_channelsout_channels1out_channels2
num_groupsr$   scale	__class__s          r   r(   DepthwiseSeparable.__init__3   sm     	1%&z)* 
  2%&%& 
r   c                J    U R                  U5      nU R                  U5      nU$ )Nr*   r+   )r,   xs     r   forwardDepthwiseSeparable.forwardO   s'      #  #r   r5   )r-   r)   r.   r)   r/   r)   r0   r)   r$   r   r1   floatreturnNoner6   r   r:   r   )r   r   r   r   r(   r7   r   __classcell__r2   s   @r   r   r   2   sV    

 
 	

 
 
 
 

8 r   r   c                  r   ^  \ 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	$ )MobileNetV1U   a;  MobileNetV1 model from
`"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_.

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 MobileNetV1 model.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import MobileNetV1

        >>> model = MobileNetV1()

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
r9   r1   r)   r   boolr   c                *  > [         TU ]  5         Xl        / U l        X l        X0l        [        S[        SU-  5      SSSS9U l        U R                  [        [        SU-  5      SSSSUS9SS	9nU R                  R                  U5        U R                  [        [        SU-  5      SS
SSUS9SS	9nU R                  R                  U5        U R                  [        [        S
U-  5      S
S
S
SUS9SS	9nU R                  R                  U5        U R                  [        [        S
U-  5      S
SS
SUS9SS	9nU R                  R                  U5        U R                  [        [        SU-  5      SSSSUS9SS	9nU R                  R                  U5        U R                  [        [        SU-  5      SSSSUS9SS	9n	U R                  R                  U	5        [        S5       HU  n
U R                  [        [        SU-  5      SSSSUS9S[        U
S-   5      -   S	9nU R                  R                  U5        MW     U R                  [        [        SU-  5      SSSSUS9SS	9nU R                  R                  U5        U R                  [        [        SU-  5      SSSSUS9SS	9nU R                  R                  U5        U(       a  [        R                  " S5      U l        US:  a)  [        R"                  " [        SU-  5      U5      U l        g g )Nr!       r
   r"   )r-   out_channelsr#   r$   r%   @   )r-   r.   r/   r0   r$   r1   conv2_1)sublayername   conv2_2conv3_1   conv3_2conv4_1i   conv4_2   conv5_i   conv5_6conv6r   )r'   r(   r1   dwslr   r   r   r)   conv1add_sublayerr   appendrangestrr   AdaptiveAvgPool2D
pool2d_avgLinearfc)r,   r1   r   r   dws21dws22dws31dws32dws41dws42itmpdws56dws6r2   s                 r   r(   MobileNetV1.__init__u   s|    	
	&"'R%Z

 !!'U
O    " 

 			!!'U
O !  " 

 			!!'e,!!  " 

 			!!'e,!!  " 

 			!!'e,!!  " 

 			!!'e,!!  " 

 			qA##+ #C%K 0"%"%" AE
* $ 
C IIS!  !!'e,!"  " 

 			  'u-""  ! 

 			 2215DO?iiD5L 1;?DG r   c                   U R                  U5      nU R                   H  nU" U5      nM     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"   )rV   rU   r   r\   r   paddleflattenr^   )r,   r6   dwss      r   r7   MobileNetV1.forward  sm    JJqM99CAA  >>"Aaq!$A
Ar   )rV   rU   r^   r   r\   r1   r   )      ?i  T)r1   r9   r   r)   r   rB   r:   r;   r<   )
r   r   r   r   __doc__r   r(   r7   r   r=   r>   s   @r   r@   r@   U   sl    6 LO 	N@N@ N@ 	N@
 
N@ N@` r   r@   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   )r@   
model_urlsr	   rk   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$ )a`  MobileNetV1 from
`"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_.

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:`MobileNetV1 <api_paddle_vision_models_MobileNetV1>`.

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

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import mobilenet_v1

        >>> # Build model
        >>> model = mobilenet_v1()

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

        >>> # build mobilenet v1 with scale=0.5
        >>> model_scale = mobilenet_v1(scale=0.5)

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
mobilenetv1_r1   )r{   rZ   )rv   r1   rw   rx   s       r   mobilenet_v1r~   %  s4    L U#Z7<@FE Lr   )F)ru   rZ   rv   rB   rw   Unpack[_MobileNetV1Options]r:   r@   )Fro   )rv   rB   r1   r9   rw   r   r:   r@   )
__future__r   typingr   r   typing_extensionsr   r   rk   r   paddle.utils.downloadr	   opsr   r   paddle._typingr   r   __all__rr   Layerr   r@   r{   r~   r   r   r   <module>r      s    #
 2   ; $$%i %
   
   F{"(( {~ #(
3N& ))) *) 	)r   