
    |j(%                    f   d dl mZ d dlmZmZ d dlmZmZ d dlZd dl	m
c mZ d dlm
Z
 d dlmZ d dlmZmZmZmZmZmZ d dlmZ d d	lmZ erd d
lmZ d dlmZ  G d de          Zg ZddiZd"dZ  G d de
j!                  Z" G d de
j!                  Z# G d de
j!                  Z$	 d#d$d!Z%dS )%    )annotations)TYPE_CHECKING	TypedDict)NotRequiredUnpackN)nn)	ParamAttr)AdaptiveAvgPool2D	AvgPool2DConv2DDropoutLinear	MaxPool2D)Uniform)get_weights_path_from_url)Tensor)Size2c                  $    e Zd ZU ded<   ded<   dS )_GoogLeNetOptionszNotRequired[int]num_classeszNotRequired[bool]	with_poolN)__name__
__module____qualname____annotations__     n/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/paddle/vision/models/googlenet.pyr   r   +   s*         %%%%$$$$$$r   r   	googlenet)zWhttps://paddle-imagenet-models-name.bj.bcebos.com/dygraph/GoogLeNet_pretrained.pdparams 80c06f038e905c53ab32c40eca6e26aechannelsintfilter_sizereturnr	   c                `    d|dz  | z  z  dz  }t          t          | |                    }|S )Ng      @   g      ?)initializer)r	   r   )r!   r#   stdv
param_attrs       r   xavierr*   :   s<    ;>H,-#5Dwud';';<<<Jr   c                  .     e Zd Z	 	 dd fd	ZddZ xZS )	ConvLayer   num_channelsr"   num_filtersr#   strider   groupsc           	         t                                                       t          |||||dz
  dz  |d          | _        d S )Nr-   r&   F)in_channelsout_channelskernel_sizer0   paddingr1   	bias_attr)super__init__r   _conv)selfr.   r/   r#   r0   r1   	__class__s         r   r9   zConvLayer.__init__A   sS     	$$# 1_*
 
 



r   inputsr   r$   c                0    |                      |          }|S )N)r:   )r;   r=   ys      r   forwardzConvLayer.forwardU   s    JJvr   )r-   r-   )
r.   r"   r/   r"   r#   r"   r0   r   r1   r"   r=   r   r$   r   r   r   r   r9   r@   __classcell__r<   s   @r   r,   r,   @   s^         
 
 
 
 
 
 
(       r   r,   c                  (     e Zd Zd fd
ZddZ xZS )	Inceptioninput_channelsr"   output_channelsfilter1filter3Rfilter3filter5Rfilter5projc	                ~   t                                                       t          ||d          | _        t          ||d          | _        t          ||d          | _        t          ||d          | _        t          ||d          | _        t          ddd          | _	        t          ||d          | _
        d S )Nr-         )r5   r0   r6   )r8   r9   r,   _conv1_conv3r_conv3_conv5r_conv5r   _pool_convprj)
r;   rG   rH   rI   rJ   rK   rL   rM   rN   r<   s
            r   r9   zInception.__init__[   s     	;; 1=='155 1=='1551QBBB
!.$::r   r=   r   r$   c                   |                      |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }t          j        ||||gd          }	t          j
        |	          }	|	S )Nr-   axis)rR   rS   rT   rU   rV   rW   rX   paddleconcatFrelu)
r;   r=   conv1conv3rconv3conv5rconv5poolconvprjcats
             r   r@   zInception.forwardq   s    F##f%%F##f%%F##zz&!!--%%mUE5':CCCfSkk
r   )rG   r"   rH   r"   rI   r"   rJ   r"   rK   r"   rL   r"   rM   r"   rN   r"   rA   rB   rD   s   @r   rF   rF   Z   sQ        ; ; ; ; ; ;,       r   rF   c                  D     e Zd ZU dZded<   ded<   dd fd
ZddZ xZS )	GoogLeNeta  GoogLeNet (Inception v1) model architecture from
    `"Going Deeper with Convolutions" <https://arxiv.org/pdf/1409.4842.pdf>`_.

    Args:
        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 GoogLeNet (Inception v1) model.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> from paddle.vision.models import GoogLeNet

            >>> # Build model
            >>> model = GoogLeNet()

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

            >>> print(out.shape, out1.shape, out2.shape)
            paddle.Size([1, 1000]) paddle.Size([1, 1000]) paddle.Size([1, 1000])
    r"   r   boolr     Tr$   Nonec           
        t                                                       || _        || _        t	          dddd          | _        t          dd          | _        t	          ddd          | _        t	          ddd          | _	        t          ddddd	d
dd          | _        t          ddd	d	dddd          | _        t          dddddd
dd          | _        t          dddddddd          | _        t          ddd	d	dddd          | _        t          dddddddd          | _        t          ddddddd	d	          | _        t          ddddddd	d	          | _        t          ddddddd	d	          | _        |r@t)          d          | _        t-          dd          | _        t-          dd          | _        |dk    r)t3          dd          | _        t7          d |t9          d d          !          | _        t	          dd	d          | _        t7          d"d t9          d#d          !          | _        t3          d$d          | _         t7          d |t9          d d          !          | _!        t	          dd	d          | _"        t7          d"d t9          d#d          !          | _#        t3          d$d          | _$        t7          d |t9          d d          !          | _%        d S d S )%NrP   @      r&   )r5   r0   r-      `                i     0   i      p            i   i  i@  i@  i  rQ   r   g?downscale_in_infer)pmodei   )weight_attri  i   gffffff?)&r8   r9   r   r   r,   r:   r   rW   _conv_1_conv_2rF   _ince3a_ince3b_ince4a_ince4b_ince4c_ince4d_ince4e_ince5a_ince5br
   _pool_5r   _pool_o1_pool_o2r   _dropr   r*   _fc_out_conv_o1_fc_o1_drop_o1_out1_conv_o2_fc_o2_drop_o2_out2)r;   r   r   r<   s      r   r9   zGoogLeNet.__init__   s   &"q"a++
1Q777
 R++ S!,, c2r3BCC c3S"b"EE c3CRDD c3S"b"EE c3S"b"EE c3S"b"EE c3S"c3GG c3S"c3GG c3S"c3GG 	?,Q//DL%!A>>>DM%!A>>>DM?? 3-ABBBDJ!kvdA  DL
 &c322DM taIIIDK#c0DEEEDMkvdAOOODJ &c322DM taIIIDK#c0DEEEDMkvdAOOODJJJ# ?r   r=   r   tuple[Tensor, Tensor, Tensor]c                   |                      |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }|                     |          }| 	                    |          }| 
                    |          }|                     |          }|                     |          }|                     |          }|||}}}| j        r?|                     |          }|                     |          }|                     |          }| j        dk    r,|                     |          }t'          j        |ddg          }|                     |          }|                     |          }t'          j        |dd          }|                     |          }t3          j        |          }|                     |          }|                     |          }|                     |          }t'          j        |dd          }|                     |          }|                     |          }|                      |          }|||fS )Nr   r&   rP   rZ   r-   )
start_axis	stop_axis)!r:   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r\   squeezer   r   flattenr   r^   r_   r   r   r   r   r   r   )	r;   r=   xince4aince4dince5boutout1out2s	            r   r@   zGoogLeNet.forward   sU   JJvJJqMMLLOOLLOOJJqMMLLOOLLOOJJqMMaLL  LLOOaLL  JJqMMLLOOa &&4T> 	',,s##C==&&D==&&Da**S//C.Aq6222C,,s##C==&&D>$1CCCD;;t$$D6$<<D==&&D::d##D==&&D>$1CCCD;;t$$D==&&D::d##DD$r   )rk   T)r   r"   r   rj   r$   rl   )r=   r   r$   r   )r   r   r   __doc__r   r9   r@   rC   rD   s   @r   ri   ri      s          6 OOO/P /P /P /P /P /P /Pb. . . . . . . .r   ri   F
pretrainedrj   kwargsUnpack[_GoogLeNetOptions]c                   t          di |}d}| rq|t          v sJ | d            t          t          |         d         t          |         d                   }t          j        |          }|                    |           |S )aC  GoogLeNet (Inception v1) model architecture from
    `"Going Deeper with Convolutions" <https://arxiv.org/pdf/1409.4842.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:`GoogLeNet <api_paddle_vision_models_GoogLeNet>`.

    Returns:
        :ref:`api_paddle_nn_Layer`. An instance of GoogLeNet (Inception v1) model.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> from paddle.vision.models import googlenet

            >>> # Build model
            >>> model = googlenet()

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

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

            >>> print(out.shape, out1.shape, out2.shape)
            paddle.Size([1, 1000]) paddle.Size([1, 1000]) paddle.Size([1, 1000])
    r   zJ model do not have a pretrained model now, you should set pretrained=Falser   r-   r   )ri   
model_urlsr   r\   loadset_dict)r   r   modelarchweight_pathparams         r   r   r     s    @ ED 	z!!!___ "!! 0tQD!1!!4
 
 K((uLr   )r!   r"   r#   r"   r$   r	   )F)r   rj   r   r   r$   ri   )&
__future__r   typingr   r   typing_extensionsr   r   r\   paddle.nn.functionalr   
functionalr^   paddle.base.param_attrr	   	paddle.nnr
   r   r   r   r   r   paddle.nn.initializerr   paddle.utils.downloadr   r   paddle._typingr   r   __all__r   r*   Layerr,   rF   ri   r   r   r   r   <module>r      sQ   # " " " " "       
 2 1 1 1 1 1 1 1                          , , , , , ,                * ) ) ) ) ) ; ; ; ; ; ; %$$$$$$% % % % %I % % %
   
          4% % % % % % % %P~ ~ ~ ~ ~ ~ ~ ~D , , , , , , ,r   