o
    #Õj®&  ã                   @   sœ   d dl Z d dl mZ d dlmZ g ZdddœZG dd„ dejƒZdd
d„Zg d¢g d¢g d¢g d¢dœZ	dd„ Z
ddd„Zddd„Zddd„Zddd„ZdS )é    N)Únn)Úget_weights_path_from_url)z7https://paddle-hapi.bj.bcebos.com/models/vgg16.pdparamsZ 89bbffc0f87d260be9b8cdc169c991c4)z7https://paddle-hapi.bj.bcebos.com/models/vgg19.pdparamsZ 23b18bb13d8894f60f54e642be79a0dd)Úvgg16Úvgg19c                       s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	ÚVGGa4  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:: python

            >>> 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)

            >>> vgg11 = VGG(features)

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

            >>> print(out.shape)
            [1, 1000]
    éè  Tc                    s|   t ƒ  ¡  || _|| _|| _|rt d¡| _|dkr<t t 	dd¡t 
¡ t ¡ t 	dd¡t 
¡ t ¡ t 	d|¡¡| _d S d S )N)é   r   r   i b  i   )ÚsuperÚ__init__ÚfeaturesÚnum_classesÚ	with_poolr   ZAdaptiveAvgPool2DÚavgpoolÚ
SequentialZLinearÚReLUZDropoutÚ
classifier)Úselfr   r   r   ©Ú	__class__© úY/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/vision/models/vgg.pyr
   B   s"   




ùÿzVGG.__init__c                 C   s>   |   |¡}| jr|  |¡}| jdkrt |d¡}|  |¡}|S )Nr   é   )r   r   r   r   ÚpaddleÚflattenr   )r   Úxr   r   r   ÚforwardV   s   



zVGG.forward)r   T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Ú__classcell__r   r   r   r   r   !   s     r   Fc                 C   s~   g }d}| D ]3}|dkr|t jdddg7 }qt j||ddd}|r/||t  |¡t  ¡ g7 }n||t  ¡ g7 }|}qt j|Ž S )Né   ÚMé   )Úkernel_sizeZstrider   )r$   Úpadding)r   Z	MaxPool2DZConv2DZBatchNorm2Dr   r   )ÚcfgÚ
batch_normZlayersZin_channelsÚvZconv2dr   r   r   Úmake_layersc   s   
r)   )é@   r"   é€   r"   é   r,   r"   é   r-   r"   r-   r-   r"   )r*   r*   r"   r+   r+   r"   r,   r,   r"   r-   r-   r"   r-   r-   r"   )r*   r*   r"   r+   r+   r"   r,   r,   r,   r"   r-   r-   r-   r"   r-   r-   r-   r"   )r*   r*   r"   r+   r+   r"   r,   r,   r,   r,   r"   r-   r-   r-   r-   r"   r-   r-   r-   r-   r"   )ÚAÚBÚDÚEc                 K   sh   t tt| |dfi |¤Ž}|r2| tv sJ | › dƒ‚tt|  d t|  d ƒ}t |¡}| |¡ |S )N)r'   zJ model do not have a pretrained model now, you should set pretrained=Falser   r   )r   r)   ÚcfgsÚ
model_urlsr   r   ÚloadÚ	load_dict)Úarchr&   r'   Ú
pretrainedÚkwargsÚmodelZweight_pathÚparamr   r   r   Ú_vgg´   s   
ÿÿ

r;   c                 K   ó&   d}|r|d7 }t |d|| fi |¤ŽS )a0  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:: python

            >>> 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)
            [1, 1000]
    Úvgg11Ú_bnr.   ©r;   ©r7   r'   r8   Z
model_namer   r   r   r=   Å   ó   r=   c                 K   r<   )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:: python

            >>> 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)
            [1, 1000]
    Úvgg13r>   r/   r?   r@   r   r   r   rB   ê   rA   rB   c                 K   r<   )a0  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:: python

            >>> 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)
            [1, 1000]
    r   r>   r0   r?   r@   r   r   r   r     rA   r   c                 K   r<   )a0  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:: python

            >>> 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)
            [1, 1000]
    r   r>   r1   r?   r@   r   r   r   r   4  rA   r   )F)FF)r   r   Zpaddle.utils.downloadr   Ú__all__r3   ZLayerr   r)   r2   r;   r=   rB   r   r   r   r   r   r   Ú<module>   s&   û
BÙA

%
%%