o
    Me5  ã                   @   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 ) a  Xception V1 model for Keras.

On ImageNet, this model gets to a top-1 validation accuracy of 0.790
and a top-5 validation accuracy of 0.945.

Reference:
  - [Xception: Deep Learning with Depthwise Separable Convolutions](
      https://arxiv.org/abs/1610.02357) (CVPR 2017)
é    N)Úbackend)Úimagenet_utils)Útraining)ÚVersionAwareLayers)Ú
data_utils)Úlayer_utils)Úkeras_exportzthttps://storage.googleapis.com/tensorflow/keras-applications/xception/xception_weights_tf_dim_ordering_tf_kernels.h5zzhttps://storage.googleapis.com/tensorflow/keras-applications/xception/xception_weights_tf_dim_ordering_tf_kernels_notop.h5z$keras.applications.xception.Xceptionzkeras.applications.XceptionTÚimagenetéè  Úsoftmaxc                 C   s~  |dv st jj |¡stdƒ‚|dkr| r|dkrtdƒ‚tj|ddt ¡ | |d�}|d	u r5t	j
|d
�}nt |¡sBt	j
||d�}n|}t ¡ dkrLdnd}t	jdddddd�|ƒ}	t	j|dd�|	ƒ}	t	jddd�|	ƒ}	t	jddddd�|	ƒ}	t	j|dd�|	ƒ}	t	jddd�|	ƒ}	t	jdd dd!dd"�|	ƒ}
t	j|d#�|
ƒ}
t	jddd!dd$d%�|	ƒ}	t	j|d&d�|	ƒ}	t	jdd'd�|	ƒ}	t	jddd!dd(d%�|	ƒ}	t	j|d)d�|	ƒ}	t	jddd!d*d+�|	ƒ}	t	 |	|
g¡}	t	jd,d dd!dd"�|	ƒ}
t	j|d#�|
ƒ}
t	jdd-d�|	ƒ}	t	jd,dd!dd.d%�|	ƒ}	t	j|d/d�|	ƒ}	t	jdd0d�|	ƒ}	t	jd,dd!dd1d%�|	ƒ}	t	j|d2d�|	ƒ}	t	jddd!d3d+�|	ƒ}	t	 |	|
g¡}	t	jd4d dd!dd"�|	ƒ}
t	j|d#�|
ƒ}
t	jdd5d�|	ƒ}	t	jd4dd!dd6d%�|	ƒ}	t	j|d7d�|	ƒ}	t	jdd8d�|	ƒ}	t	jd4dd!dd9d%�|	ƒ}	t	j|d:d�|	ƒ}	t	jddd!d;d+�|	ƒ}	t	 |	|
g¡}	td<ƒD ]€}|	}
d=t|d> ƒ }t	jd|d? d�|	ƒ}	t	jd4dd!d|d@ d%�|	ƒ}	t	j||dA d�|	ƒ}	t	jd|dB d�|	ƒ}	t	jd4dd!d|dC d%�|	ƒ}	t	j||dD d�|	ƒ}	t	jd|dE d�|	ƒ}	t	jd4dd!d|dF d%�|	ƒ}	t	j||dG d�|	ƒ}	t	 |	|
g¡}	�qªt	jdHd dd!dd"�|	ƒ}
t	j|d#�|
ƒ}
t	jddId�|	ƒ}	t	jd4dd!ddJd%�|	ƒ}	t	j|dKd�|	ƒ}	t	jddLd�|	ƒ}	t	jdHdd!ddMd%�|	ƒ}	t	j|dNd�|	ƒ}	t	jddd!dOd+�|	ƒ}	t	 |	|
g¡}	t	jdPdd!ddQd%�|	ƒ}	t	j|dRd�|	ƒ}	t	jddSd�|	ƒ}	t	jdTdd!ddUd%�|	ƒ}	t	j|dVd�|	ƒ}	t	jddWd�|	ƒ}	| �råt	jdXd�|	ƒ}	t ||¡ t	j||dYdZ�|	ƒ}	n|d[k�rñt	 ¡ |	ƒ}	n|d\k�rüt	 ¡ |	ƒ}	|d	u�rt |¡}n|}tj||	d]d�}|dk�r3| �r#tjd^td_d`da�}n	tjdbtd_dcda�}|  |¡ |S |d	u�r=|  |¡ |S )daU
  Instantiates the Xception architecture.

    Reference:
    - [Xception: Deep Learning with Depthwise Separable Convolutions](
        https://arxiv.org/abs/1610.02357) (CVPR 2017)

    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 image size for this model is 299x299.

    Note: each Keras Application expects a specific kind of input preprocessing.
    For Xception, call `tf.keras.applications.xception.preprocess_input` on your
    inputs before passing them to the model.
    `xception.preprocess_input` will scale input pixels between -1 and 1.

    Args:
      include_top: whether to include the fully-connected
        layer 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 `(299, 299, 3)`.
        It should have exactly 3 inputs channels,
        and width and height should be no smaller than 71.
        E.g. `(150, 150, 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.r	   r
   zWIf using `weights` as `"imagenet"` with `include_top` as true, `classes` should be 1000i+  éG   )Zdefault_sizeZmin_sizeÚdata_formatZrequire_flattenÚweightsN)Úshape)Ztensorr   Zchannels_firsté   éÿÿÿÿé    )é   r   )é   r   FZblock1_conv1)ÚstridesÚuse_biasÚnameZblock1_conv1_bn)Úaxisr   ZreluZblock1_conv1_act)r   é@   Zblock1_conv2)r   r   Zblock1_conv2_bnZblock1_conv2_acté€   )r   r   Zsame)r   Úpaddingr   )r   Zblock2_sepconv1)r   r   r   Zblock2_sepconv1_bnZblock2_sepconv2_actZblock2_sepconv2Zblock2_sepconv2_bnZblock2_pool)r   r   r   é   Zblock3_sepconv1_actZblock3_sepconv1Zblock3_sepconv1_bnZblock3_sepconv2_actZblock3_sepconv2Zblock3_sepconv2_bnZblock3_pooliØ  Zblock4_sepconv1_actZblock4_sepconv1Zblock4_sepconv1_bnZblock4_sepconv2_actZblock4_sepconv2Zblock4_sepconv2_bnZblock4_poolé   Úblocké   Z_sepconv1_actZ	_sepconv1Z_sepconv1_bnZ_sepconv2_actZ	_sepconv2Z_sepconv2_bnZ_sepconv3_actZ	_sepconv3Z_sepconv3_bni   Zblock13_sepconv1_actZblock13_sepconv1Zblock13_sepconv1_bnZblock13_sepconv2_actZblock13_sepconv2Zblock13_sepconv2_bnZblock13_pooli   Zblock14_sepconv1Zblock14_sepconv1_bnZblock14_sepconv1_acti   Zblock14_sepconv2Zblock14_sepconv2_bnZblock14_sepconv2_actZavg_poolZpredictions)Z
activationr   ZavgÚmaxZxceptionz.xception_weights_tf_dim_ordering_tf_kernels.h5ÚmodelsZ 0a58e3b7378bc2990ea3b43d5981f1f6)Zcache_subdirZ	file_hashz4xception_weights_tf_dim_ordering_tf_kernels_notop.h5Z b0042744bf5b25fce3cb969f33bebb97)!ÚtfÚioZgfileÚexistsÚ
ValueErrorr   Zobtain_input_shaper   Zimage_data_formatÚlayersZInputZis_keras_tensorZConv2DZBatchNormalizationZ
ActivationZSeparableConv2DZMaxPooling2DÚaddÚrangeÚstrZGlobalAveragePooling2DZvalidate_activationZDenseZGlobalMaxPooling2Dr   Zget_source_inputsr   ZModelr   Zget_fileÚTF_WEIGHTS_PATHÚTF_WEIGHTS_PATH_NO_TOPZload_weights)Zinclude_topr   Zinput_tensorZinput_shapeZpoolingÚclassesZclassifier_activationZ	img_inputZchannel_axisÚxZresidualÚiÚprefixZinputsÚmodelZweights_path© r1   úKD:\Projects\ConvertPro\env\Lib\site-packages\keras/applications/xception.pyÚXception2   s
  Gÿÿú	

ÿþ
ÿþ
ÿþÿ
ÿþÿÿþ
ÿþ
ÿþÿ
ÿþÿÿþ
ÿþ
ÿþÿ
ÿþÿÿþûúÿþûúÿþûúÿþ
ÿþ
ÿþÿþ
ÿþÿþÿþ
ÿþÿþ
ÿþÿþÿþ



üü

ý
r3   z,keras.applications.xception.preprocess_inputc                 C   s   t j| |dd�S )Nr"   )r   Úmode)r   Úpreprocess_input)r-   r   r1   r1   r2   r5   k  s   ÿr5   z.keras.applications.xception.decode_predictionsr   c                 C   s   t j| |d�S )N)Útop)r   Údecode_predictions)Úpredsr6   r1   r1   r2   r7   r  s   r7   Ú )r4   Ú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&   r3   r5   r7   ZPREPROCESS_INPUT_DOCÚformatZPREPROCESS_INPUT_RET_DOC_TFZPREPROCESS_INPUT_ERROR_DOCr1   r1   r1   r2   Ú<module>   sJ   
ÿÿÿù  8ý