B
    «»ˆdZ  ã               @   sn   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 edƒG d	d
„ d
eƒƒZdS )z%Keras upsampling layer for 2D inputs.é    N)Úbackend)ÚLayer)Ú	InputSpec)Ú
conv_utils)Úkeras_exportzkeras.layers.UpSampling2Dc                   s>   e Zd ZdZd‡ fdd„	Zdd„ Zd	d
„ Z‡ fdd„Z‡  ZS )ÚUpSampling2Da¢  Upsampling layer for 2D inputs.

    Repeats the rows and columns of the data
    by `size[0]` and `size[1]` respectively.

    Examples:

    >>> input_shape = (2, 2, 1, 3)
    >>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
    >>> print(x)
    [[[[ 0  1  2]]
      [[ 3  4  5]]]
     [[[ 6  7  8]]
      [[ 9 10 11]]]]
    >>> y = tf.keras.layers.UpSampling2D(size=(1, 2))(x)
    >>> print(y)
    tf.Tensor(
      [[[[ 0  1  2]
         [ 0  1  2]]
        [[ 3  4  5]
         [ 3  4  5]]]
       [[[ 6  7  8]
         [ 6  7  8]]
        [[ 9 10 11]
         [ 9 10 11]]]], shape=(2, 2, 2, 3), dtype=int64)

    Args:
      size: Int, or tuple of 2 integers.
        The upsampling factors for rows and columns.
      data_format: A string,
        one of `channels_last` (default) or `channels_first`.
        The ordering of the dimensions in the inputs.
        `channels_last` corresponds to inputs with shape
        `(batch_size, height, width, channels)` while `channels_first`
        corresponds to inputs with shape
        `(batch_size, channels, height, width)`.
        It defaults to the `image_data_format` value found in your
        Keras config file at `~/.keras/keras.json`.
        If you never set it, then it will be "channels_last".
      interpolation: A string, one of `"area"`, `"bicubic"`, `"bilinear"`,
        `"gaussian"`, `"lanczos3"`, `"lanczos5"`, `"mitchellcubic"`,
        `"nearest"`.

    Input shape:
      4D tensor with shape:
      - If `data_format` is `"channels_last"`:
          `(batch_size, rows, cols, channels)`
      - If `data_format` is `"channels_first"`:
          `(batch_size, channels, rows, cols)`

    Output shape:
      4D tensor with shape:
      - If `data_format` is `"channels_last"`:
          `(batch_size, upsampled_rows, upsampled_cols, channels)`
      - If `data_format` is `"channels_first"`:
          `(batch_size, channels, upsampled_rows, upsampled_cols)`
    ©é   r	   NÚnearestc          	      sº   t ƒ jf |Ž t |¡| _t |dd¡| _tjj	j
tjj	jtjj	jtjj	jtjj	jtjj	jtjj	jtjj	jdœ}dd | ¡ ¡ d }||kr¤td|› d|› dƒ‚|| _td	d
| _d S )Nr	   Úsize)ZareaZbicubicZbilinearZgaussianZlanczos3Zlanczos5Zmitchellcubicr
   ú"z", "z+`interpolation` argument should be one of: z. Received: "z".é   )Úndim)ÚsuperÚ__init__r   Znormalize_data_formatÚdata_formatZnormalize_tupler   ÚtfÚimageZResizeMethodZAREAZBICUBICZBILINEARZGAUSSIANZLANCZOS3ZLANCZOS5ZMITCHELLCUBICZNEAREST_NEIGHBORÚjoinÚkeysÚ
ValueErrorÚinterpolationr   Z
input_spec)Úselfr   r   r   ÚkwargsZinterpolationsZinterploations_list)Ú	__class__© úV/var/www/html/venv/lib/python3.7/site-packages/keras/layers/reshaping/up_sampling2d.pyr   Y   s"    zUpSampling2D.__init__c             C   sØ   t  |¡ ¡ }| jdkrv|d d k	r6| jd |d  nd }|d d k	rX| jd |d  nd }t  |d |d ||g¡S |d d k	r”| jd |d  nd }|d d k	r¶| jd |d  nd }t  |d |||d g¡S d S )NZchannels_firstr	   r   é   é   )r   ZTensorShapeÚas_listr   r   )r   Zinput_shapeÚheightÚwidthr   r   r   Úcompute_output_shaper   s    
z!UpSampling2D.compute_output_shapec             C   s$   t j|| jd | jd | j| jdS )Nr   r   )r   )r   Zresize_imagesr   r   r   )r   Úinputsr   r   r   Úcall‘   s    zUpSampling2D.callc                s8   | j | j| jdœ}tƒ  ¡ }tt| ¡ ƒt| ¡ ƒ ƒS )N)r   r   r   )r   r   r   r   Ú
get_configÚdictÚlistÚitems)r   ÚconfigZbase_config)r   r   r   r%   š   s
    

zUpSampling2D.get_config)r   Nr
   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r$   r%   Ú__classcell__r   r   )r   r   r      s
   :	r   )r-   Ztensorflow.compat.v2ÚcompatZv2r   Zkerasr   Zkeras.engine.base_layerr   Zkeras.engine.input_specr   Zkeras.utilsr   Z tensorflow.python.util.tf_exportr   r   r   r   r   r   Ú<module>   s   