Ë
    –\;j(  ã                   ó¨   — d dl Z d dl mZ d dlmZ g ZdddœZ G d„ dej                  «      Zdd	„Zg d
¢g d¢g d¢g d¢dœZ	d„ Z
dd„Zdd„Zdd„Zdd„Zy)é    N)Únn)Úget_weights_path_from_url)z7https://paddle-hapi.bj.bcebos.com/models/vgg16.pdparamsÚ 89bbffc0f87d260be9b8cdc169c991c4)z7https://paddle-hapi.bj.bcebos.com/models/vgg19.pdparamsÚ 23b18bb13d8894f60f54e642be79a0dd)Úvgg16Úvgg19c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ x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]
    c                 óØ  •— t         ‰| �  «        || _        || _        || _        |rt        j                  d«      | _        |dkD  r¥t        j                  t        j                  dd«      t        j                  «       t        j                  «       t        j                  dd«      t        j                  «       t        j                  «       t        j                  d|«      «      | _        y y )N)é   r   r   i b  i   )ÚsuperÚ__init__ÚfeaturesÚnum_classesÚ	with_poolr   ÚAdaptiveAvgPool2DÚavgpoolÚ
SequentialÚLinearÚReLUÚDropoutÚ
classifier)Úselfr   r   r   Ú	__class__s       €úaG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/vision/models/vgg.pyr   zVGG.__init__B   s£   ø€ Ü‰ÑÔØ ˆŒØ&ˆÔØ"ˆŒáÜ×/Ñ/°Ó7ˆDŒLà˜Š?Ü Ÿm™mÜ—	‘	˜+ tÓ,Ü—‘“	Ü—
‘
“Ü—	‘	˜$ Ó%Ü—‘“	Ü—
‘
“Ü—	‘	˜$ Ó,óˆD�Oð ó    c                 óÎ   — | j                  |«      }| j                  r| j                  |«      }| j                  dkD  r't	        j
                  |d«      }| j                  |«      }|S )Nr   é   )r   r   r   r   ÚpaddleÚflattenr   )r   Úxs     r   ÚforwardzVGG.forwardV   sU   € Ø�M‰M˜!Óˆà�>Š>Ø—‘˜Q“ˆAà×Ñ˜aÒÜ—‘˜q !Ó$ˆAØ—‘ Ó"ˆAàˆr   )iè  T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   Ú__classcell__)r   s   @r   r
   r
   !   s   ø„ ñõ@ö(
r   r
   c                 óF  — g }d}| D ]‡  }|dk(  r|t        j                  dd¬«      gz  }Œ$t        j                  ||dd¬«      }|r.||t        j                  |«      t        j                  «       gz  }n||t        j                  «       gz  }|}Œ‰ t        j
                  |Ž S )Né   ÚMé   )Úkernel_sizeÚstrider   )r,   Úpadding)r   Ú	MaxPool2DÚConv2DÚBatchNorm2Dr   r   )ÚcfgÚ
batch_normÚlayersÚin_channelsÚvÚconv2ds         r   Úmake_layersr8   c   s—   € Ø€FØ€KÛˆØ�Š8Ø”r—|‘|°¸!Ô<Ð=Ñ=‰Fä—Y‘Y˜{¨A¸1ÀaÔHˆFÙØ˜6¤2§>¡>°!Ó#4´b·g±g³iÐ@Ñ@‘à˜6¤2§7¡7£9Ð-Ñ-�Ø‰Kð ô �=‰=˜&Ð!Ð!r   )é@   r*   é€   r*   é   r;   r*   é   r<   r*   r<   r<   r*   )r9   r9   r*   r:   r:   r*   r;   r;   r*   r<   r<   r*   r<   r<   r*   )r9   r9   r*   r:   r:   r*   r;   r;   r;   r*   r<   r<   r<   r*   r<   r<   r<   r*   )r9   r9   r*   r:   r:   r*   r;   r;   r;   r;   r*   r<   r<   r<   r<   r*   r<   r<   r<   r<   r*   )ÚAÚBÚDÚEc                 óö   — t        t        t        |   |¬«      fi |¤Ž}|rX| t        v s
J | › d�«       ‚t	        t        |    d   t        |    d   «      }t        j                  |«      }|j                  |«       |S )N)r3   zJ model do not have a pretrained model now, you should set pretrained=Falser   r   )r
   r8   ÚcfgsÚ
model_urlsr   r   ÚloadÚ	load_dict)Úarchr2   r3   Ú
pretrainedÚkwargsÚmodelÚweight_pathÚparams           r   Ú_vggrL   ´   s…   € Ü”œD ™I°*Ô=ÑHÀÑH€Eáà”JÑð	_àˆVÐ]Ð^ó	_Øä/Ü�tÑ˜QÑ¤¨DÑ!1°!Ñ!4ó
ˆô —‘˜KÓ(ˆØ�‰˜Ôà€Lr   c                 ó2   — d}|r|dz  }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=   ©rL   ©rG   r3   rH   Ú
model_names       r   rN   rN   Å   ó,   € ð> €JÙØ�eÑˆ
Ü�
˜C ¨ZÑB¸6ÑBÐBr   c                 ó2   — d}|r|dz  }t        |d|| fi |¤ŽS )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]
    Úvgg13rO   r>   rP   rQ   s       r   rU   rU   ê   rS   r   c                 ó2   — d}|r|dz  }t        |d|| fi |¤ŽS )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   rO   r?   rP   rQ   s       r   r   r     rS   r   c                 ó2   — d}|r|dz  }t        |d|| fi |¤ŽS )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   rO   r@   rP   rQ   s       r   r   r   4  rS   r   )F)FF)r   r   Úpaddle.utils.downloadr   Ú__all__rC   ÚLayerr
   r8   rB   rL   rN   rU   r   r   © r   r   Ú<module>r\      sz   ðó Ý Ý ;à
€ððñ	€
ô?ˆ"�(‰(ô ?óD"ò" 
Jò
ò"
ò(
ñO>€òBó""CóJ"CóJ"CôJ"Cr   