
    ёij*                       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  \(       a  S SK	Jr  S SKJrJr   " S	 S
\5      r/ rSSS.r " S S\
R                  5      r S     SS jjr/ SQ/ SQ/ SQ/ SQS.r            SS jr  S       SS jjr  S       SS jjr  S       SS jjr  S       SS jjrg)     )annotations)TYPE_CHECKINGLiteral	TypedDict)NotRequiredUnpackN)nn)get_weights_path_from_url)Tensor)Layer
Sequentialc                  *    \ rS rSr% S\S'   S\S'   Srg)_VGGOptions!   zNotRequired[int]num_classeszNotRequired[bool]	with_pool N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r       X/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/vision/models/vgg.pyr   r   !   s    %%$$r   r   )z7https://paddle-hapi.bj.bcebos.com/models/vgg16.pdparams 89bbffc0f87d260be9b8cdc169c991c4)z7https://paddle-hapi.bj.bcebos.com/models/vgg19.pdparams 23b18bb13d8894f60f54e642be79a0dd)vgg16vgg19c                  d   ^  \ 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	$ )VGG4   a  VGG model from
`"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_.

Args:
    features (nn.Layer): Vgg features create by function make_layers.
    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 three fc layer or not. Default: True.

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

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import VGG
        >>> from paddle.vision.models.vgg import make_layers

        >>> vgg11_cfg = [
        ...     64,
        ...     'M',
        ...     128,
        ...     'M',
        ...     256,
        ...     256,
        ...     'M',
        ...     512,
        ...     512,
        ...     'M',
        ...     512,
        ...     512,
        ...     'M',
        ... ]

        >>> features = make_layers(vgg11_cfg)  # type: ignore

        >>> vgg11 = VGG(features)

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
intr   boolr   c                  > [         TU ]  5         Xl        X l        X0l        U(       a  [
        R                  " S5      U l        US:  a  [
        R                  " [
        R                  " SS5      [
        R                  " 5       [
        R                  " 5       [
        R                  " SS5      [
        R                  " 5       [
        R                  " 5       [
        R                  " SU5      5      U l        g g )N)   r&   r   i b  i   )super__init__featuresr   r   r	   AdaptiveAvgPool2Davgpoolr   LinearReLUDropout
classifier)selfr)   r   r   	__class__s       r   r(   VGG.__init__f   s     	 &"//7DL? mm		+t,	

		$%	

		$,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   paddleflattenr/   )r0   xs     r   forwardVGG.forward|   sU    MM!>>QAaq!$A"Ar   )r+   r/   r)   r   r   )i  T)r)   r   r   r#   r   r$   returnNone)r7   r   r:   r   )
r   r   r   r   __doc__r   r(   r8   r   __classcell__)r1   s   @r   r!   r!   4   sQ    ,\ O KO,/CG	 ,
 
r   r!   c                R   / nSnU  H  nUS:X  a  U[         R                  " SSS9/-  nM$  [         R                  " X4SSS9nU(       a/  X%[         R                  " U5      [         R                  " 5       /-  nOX%[         R                  " 5       /-  nUnM     [         R
                  " U6 $ )N   M   )kernel_sizestrider4   )rB   padding)r	   	MaxPool2DConv2DBatchNorm2Dr-   r   )cfg
batch_normlayersin_channelsvconv2ds         r   make_layersrN      s     FK8r||!<==FYY{1aHF2>>!#4bggi@@2779--K  ==&!!r   )@   r@      r@      rQ   r@      rR   r@   rR   rR   r@   )rO   rO   r@   rP   rP   r@   rQ   rQ   r@   rR   rR   r@   rR   rR   r@   )rO   rO   r@   rP   rP   r@   rQ   rQ   rQ   r@   rR   rR   rR   r@   rR   rR   rR   r@   )rO   rO   r@   rP   rP   r@   rQ   rQ   rQ   rQ   r@   rR   rR   rR   rR   r@   rR   rR   rR   rR   r@   )ABDEc                    [        [        [        U   US94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$ )N)rI   zJ model do not have a pretrained model now, you should set pretrained=Falser   r4   )r!   rN   cfgs
model_urlsr
   r5   load	load_dict)archrH   rI   
pretrainedkwargsmodelweight_pathparams           r   _vggrb      s     DI*=HHEz! 	
f^_	
! 0tQD!1!!4
 K(Lr   c                :    SnU(       a  US-  n[        USX40 UD6$ )a  VGG 11-layer model from
`"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_.

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

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of VGG 11-layer model.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import vgg11

        >>> # build model
        >>> model = vgg11()

        >>> # build vgg11 model with batch_norm
        >>> model = vgg11(batch_norm=True)

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
vgg11_bnrS   rb   r]   rI   r^   
model_names       r   rd   rd      +    F Je

CB6BBr   c                :    SnU(       a  US-  n[        USX40 UD6$ )a  VGG 13-layer model from
`"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_.

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

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of VGG 13-layer model.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import vgg13

        >>> # build model
        >>> model = vgg13()

        >>> # build vgg13 model with batch_norm
        >>> model = vgg13(batch_norm=True)

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
vgg13re   rT   rf   rg   s       r   rk   rk      ri   r   c                :    SnU(       a  US-  n[        USX40 UD6$ )a  VGG 16-layer model from
`"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_.

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

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of VGG 16-layer model.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import vgg16

        >>> # build model
        >>> model = vgg16()

        >>> # build vgg16 model with batch_norm
        >>> model = vgg16(batch_norm=True)

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   re   rU   rf   rg   s       r   r   r   $  ri   r   c                :    SnU(       a  US-  n[        USX40 UD6$ )a  VGG 19-layer model from
`"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_.

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

Returns:
    :ref:`api_paddle_nn_Layer`. An instance of VGG 19-layer model.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.models import vgg19

        >>> # build model
        >>> model = vgg19()

        >>> # build vgg19 model with batch_norm
        >>> model = vgg19(batch_norm=True)

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

        >>> print(out.shape)
        paddle.Size([1, 1000])
r   re   rV   rf   rg   s       r   r   r   M  ri   r   )F)rH   zlist[int | Literal['M']]rI   r$   r:   r   )r\   strrH   zLiteral['A', 'B', 'D', 'E']rI   r$   r]   r$   r^   Unpack[_VGGOptions]r:   r!   )FF)r]   r$   rI   r$   r^   ro   r:   r!   )
__future__r   typingr   r   r   typing_extensionsr   r   r5   r	   paddle.utils.downloadr
   r   	paddle.nnr   r   r   __all__rY   r!   rN   rX   rb   rd   rk   r   r   r   r   r   <module>rv      s   #  2   ;+%i %
 	
R"(( Rl 7<"	!"/3""&



-@
	$  	
 " 	0 &C&C&C "&C 		&CT &C&C&C "&C 		&CT &C&C&C "&C 		&CT &C&C&C "&C 		&Cr   