a
    SicZ                     @   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 i | 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 }||vrtd| d| d|| _td	d
| _d S )Nr	   size)areabicubicbilineargaussianlanczos3lanczos5mitchellcubicr
   "z", "z+`interpolation` argument should be one of: z. Received: "z".   )ndim)super__init__r   normalize_data_formatdata_formatnormalize_tupler   tfimageResizeMethodAREABICUBICBILINEARGAUSSIANLANCZOS3LANCZOS5MITCHELLCUBICNEAREST_NEIGHBORjoinkeys
ValueErrorinterpolationr   
input_spec)selfr   r   r)   kwargsinterpolationsinterploations_list	__class__ `/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/layers/reshaping/up_sampling2d.pyr   Y   s.    
zUpSampling2D.__init__c                 C   s   t | }| jdkrv|d d ur6| jd |d  nd }|d d urX| jd |d  nd }t |d |d ||gS |d d ur| jd |d  nd }|d d ur| jd |d  nd }t |d |||d gS d S )Nchannels_firstr	   r         )r   TensorShapeas_listr   r   )r+   input_shapeheightwidthr1   r1   r2   compute_output_shaper   s0    




z!UpSampling2D.compute_output_shapec                 C   s$   t j|| jd | jd | j| jdS )Nr   r5   )r)   )r   resize_imagesr   r   r)   )r+   inputsr1   r1   r2   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+   configbase_configr/   r1   r2   r?      s    
zUpSampling2D.get_config)r   Nr
   )	__name__
__module____qualname____doc__r   r;   r>   r?   __classcell__r1   r1   r/   r2   r      s   ; 	r   )rH   tensorflow.compat.v2compatv2r   kerasr   keras.engine.base_layerr   keras.engine.input_specr   keras.utilsr    tensorflow.python.util.tf_exportr   r   r1   r1   r1   r2   <module>   s   