o
    Me$(  ã                   @   sä   d Z ddlm  mZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ d
ZdZeƒ Zeddƒ							ddd„ƒZedƒddd„ƒZedƒddd„ƒZejjdejejd�e_ ejj e_ dS ) z VGG19 model for Keras.

Reference:
  - [Very Deep Convolutional Networks for Large-Scale Image Recognition](
      https://arxiv.org/abs/1409.1556) (ICLR 2015)
é    N)Úbackend)Úimagenet_utils)Útraining)ÚVersionAwareLayers)Ú
data_utils)Úlayer_utils)Úkeras_exportznhttps://storage.googleapis.com/tensorflow/keras-applications/vgg19/vgg19_weights_tf_dim_ordering_tf_kernels.h5zthttps://storage.googleapis.com/tensorflow/keras-applications/vgg19/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5zkeras.applications.vgg19.VGG19zkeras.applications.VGG19TÚimagenetéè  Úsoftmaxc                 C   s�  |dv st jj |¡std|› d�ƒ‚|dkr%| r%|dkr%td|› d�ƒ‚tj|ddt ¡ | |d	�}|d
u r=t	j
|d�}nt |¡sJt	j
||d�}n|}t	jdddddd�|ƒ}t	jdddddd�|ƒ}t	jdddd�|ƒ}t	jdddddd�|ƒ}t	jdddddd�|ƒ}t	jdddd�|ƒ}t	jdddddd�|ƒ}t	jdddddd�|ƒ}t	jdddddd�|ƒ}t	jdddddd�|ƒ}t	jddd d�|ƒ}t	jd!dddd"d�|ƒ}t	jd!dddd#d�|ƒ}t	jd!dddd$d�|ƒ}t	jd!dddd%d�|ƒ}t	jddd&d�|ƒ}t	jd!dddd'd�|ƒ}t	jd!dddd(d�|ƒ}t	jd!dddd)d�|ƒ}t	jd!dddd*d�|ƒ}t	jddd+d�|ƒ}| �rnt	jd,d-�|ƒ}t	jd.dd/d0�|ƒ}t	jd.dd1d0�|ƒ}t ||¡ t	j||d2d0�|ƒ}n|d3k�rzt	 ¡ |ƒ}n|d4k�r…t	 ¡ |ƒ}|d
u�r�t |¡}	n|}	tj|	|d5d-�}
|dk�r¼| �r¬tjd6td7d8d9�}n	tjd:td7d;d9�}|
 |¡ |
S |d
u�rÆ|
 |¡ |
S )<a%  Instantiates the VGG19 architecture.

    Reference:
    - [Very Deep Convolutional Networks for Large-Scale Image Recognition](
        https://arxiv.org/abs/1409.1556) (ICLR 2015)

    For image classification use cases, see
    [this page for detailed examples](
      https://keras.io/api/applications/#usage-examples-for-image-classification-models).

    For transfer learning use cases, make sure to read the
    [guide to transfer learning & fine-tuning](
      https://keras.io/guides/transfer_learning/).

    The default input size for this model is 224x224.

    Note: each Keras Application expects a specific kind of input preprocessing.
    For VGG19, call `tf.keras.applications.vgg19.preprocess_input` on your
    inputs before passing them to the model.
    `vgg19.preprocess_input` will convert the input images from RGB to BGR,
    then will zero-center each color channel with respect to the ImageNet
    dataset, without scaling.

    Args:
      include_top: whether to include the 3 fully-connected
        layers at the top of the network.
      weights: one of `None` (random initialization),
          'imagenet' (pre-training on ImageNet),
          or the path to the weights file to be loaded.
      input_tensor: optional Keras tensor
        (i.e. output of `layers.Input()`)
        to use as image input for the model.
      input_shape: optional shape tuple, only to be specified
        if `include_top` is False (otherwise the input shape
        has to be `(224, 224, 3)`
        (with `channels_last` data format)
        or `(3, 224, 224)` (with `channels_first` data format).
        It should have exactly 3 inputs channels,
        and width and height should be no smaller than 32.
        E.g. `(200, 200, 3)` would be one valid value.
      pooling: Optional pooling mode for feature extraction
        when `include_top` is `False`.
        - `None` means that the output of the model will be
            the 4D tensor output of the
            last convolutional block.
        - `avg` means that global average pooling
            will be applied to the output of the
            last convolutional block, and thus
            the output of the model will be a 2D tensor.
        - `max` means that global max pooling will
            be applied.
      classes: optional number of classes to classify images
        into, only to be specified if `include_top` is True, and
        if no `weights` argument is specified.
      classifier_activation: A `str` or callable. The activation function to use
        on the "top" layer. Ignored unless `include_top=True`. Set
        `classifier_activation=None` to return the logits of the "top" layer.
        When loading pretrained weights, `classifier_activation` can only
        be `None` or `"softmax"`.

    Returns:
      A `keras.Model` instance.
    >   r	   Nz±The `weights` argument should be either `None` (random initialization), `imagenet` (pre-training on ImageNet), or the path to the weights file to be loaded.  Received: `weights=z.`r	   r
   zmIf using `weights` as `"imagenet"` with `include_top` as true, `classes` should be 1000.  Received: `classes=éà   é    )Zdefault_sizeZmin_sizeÚdata_formatZrequire_flattenÚweightsN)Úshape)Ztensorr   é@   )é   r   ZreluZsameZblock1_conv1)Ú
activationÚpaddingÚnameZblock1_conv2)é   r   Zblock1_pool)Ústridesr   é€   Zblock2_conv1Zblock2_conv2Zblock2_poolé   Zblock3_conv1Zblock3_conv2Zblock3_conv3Zblock3_conv4Zblock3_pooli   Zblock4_conv1Zblock4_conv2Zblock4_conv3Zblock4_conv4Zblock4_poolZblock5_conv1Zblock5_conv2Zblock5_conv3Zblock5_conv4Zblock5_poolÚflatten)r   i   Zfc1)r   r   Zfc2ZpredictionsZavgÚmaxZvgg19z+vgg19_weights_tf_dim_ordering_tf_kernels.h5ÚmodelsZ cbe5617147190e668d6c5d5026f83318)Zcache_subdirZ	file_hashz1vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5Z 253f8cb515780f3b799900260a226db6)ÚtfÚioZgfileÚexistsÚ
ValueErrorr   Zobtain_input_shaper   Zimage_data_formatÚlayersZInputZis_keras_tensorZConv2DZMaxPooling2DZFlattenZDenseZvalidate_activationZGlobalAveragePooling2DZGlobalMaxPooling2Dr   Zget_source_inputsr   ZModelr   Zget_fileÚWEIGHTS_PATHÚWEIGHTS_PATH_NO_TOPZload_weights)Zinclude_topr   Zinput_tensorZinput_shapeZpoolingÚclassesZclassifier_activationZ	img_inputÚxZinputsÚmodelZweights_path© r'   úHD:\Projects\ConvertPro\env\Lib\site-packages\keras/applications/vgg19.pyÚVGG190   s&  Iüÿþÿú	

ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþ
ÿþÿþ



üü

ý
r)   z)keras.applications.vgg19.preprocess_inputc                 C   s   t j| |dd�S )NZcaffe)r   Úmode)r   Úpreprocess_input)r%   r   r'   r'   r(   r+     s   ÿr+   z+keras.applications.vgg19.decode_predictionsé   c                 C   s   t j| |d�S )N)Útop)r   Údecode_predictions)Úpredsr-   r'   r'   r(   r.     s   r.   Ú )r*   ÚretÚerror)Tr	   NNNr
   r   )N)r,   )Ú__doc__Ztensorflow.compat.v2ÚcompatÚv2r   Zkerasr   Zkeras.applicationsr   Zkeras.enginer   Zkeras.layersr   Zkeras.utilsr   r   Z tensorflow.python.util.tf_exportr   r"   r#   r!   r)   r+   r.   ZPREPROCESS_INPUT_DOCÚformatZPREPROCESS_INPUT_RET_DOC_CAFFEZPREPROCESS_INPUT_ERROR_DOCr'   r'   r'   r(   Ú<module>   sD   ÿÿù Wý