o
    i e                     @   sz   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 ed	G d
d deZdS )z%Keras upsampling layer for 2D inputs.    N)backend)Layer)	InputSpec)
conv_utils)image_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)`.
        When unspecified, uses
        `image_data_format` value found in your Keras config file at
         `~/.keras/keras.json` (if exists) else 'channels_last'.
        Defaults to '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                    sJ   t  jdi | t|| _t|dd| _t|| _	t
dd| _d S )Nr
   size   )ndim )super__init__r   normalize_data_formatdata_formatnormalize_tupler   r   get_interpolationinterpolationr   
input_spec)selfr   r   r   kwargs	__class__r   W/var/www/myenv/lib/python3.10/site-packages/keras/src/layers/reshaping/up_sampling2d.pyr   [   s
   zUpSampling2D.__init__c                 C   s   t | }| jdkr;|d d ur| jd |d  nd }|d d ur,| jd |d  nd }t |d |d ||gS |d d urJ| jd |d  nd }|d d ur[| jd |d  nd }t |d |||d gS )Nchannels_firstr
   r         )tfTensorShapeas_listr   r   )r   input_shapeheightwidthr   r   r   compute_output_shaped   s0   
z!UpSampling2D.compute_output_shapec                 C   s$   t j|| jd | jd | j| jdS )Nr   r   )r   )r   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   configbase_configr   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   )r3   tensorflow.compat.v2compatv2r    	keras.srcr   keras.src.engine.base_layerr   keras.src.engine.input_specr   keras.src.utilsr   r    tensorflow.python.util.tf_exportr   r   r   r   r   r   <module>   s   