
    2Vh                     x    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	e             Zy
)    )backend)ops)keras_export)	InputSpec)Layer)argument_validationzkeras.layers.UpSampling2Dc                   F     e Zd ZdZ	 d fd	Zd Zd Z fdZ	 ddZ xZ	S )	UpSampling2Da  Upsampling layer for 2D inputs.

    The implementation uses interpolative resizing, given the resize method
    (specified by the `interpolation` argument). Use `interpolation=nearest`
    to repeat the rows and columns of the data.

    Example:

    >>> 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 = keras.layers.UpSampling2D(size=(1, 2))(x)
    >>> print(y)
    [[[[ 0  1  2]
       [ 0  1  2]]
      [[ 3  4  5]
       [ 3  4  5]]]
     [[[ 6  7  8]
       [ 6  7  8]]
      [[ 9 10 11]
       [ 9 10 11]]]]

    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 `"bicubic"`, `"bilinear"`, `"lanczos3"`,
            `"lanczos5"`, `"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)`
    c                     t        |   di | t        j                  |      | _        t        j                  |dd      | _        |j                         | _	        t        d      | _        y )N   size   )ndim )super__init__r   standardize_data_formatdata_formatr   standardize_tupler   lowerinterpolationr   
input_spec)selfr   r   r   kwargs	__class__s        X/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/layers/reshaping/up_sampling2d.pyr   zUpSampling2D.__init__E   s[     	"6""::;G'99$6J	*002#+    c                 0   | j                   dk(  rD|d   | j                  d   |d   z  nd }|d   | j                  d   |d   z  nd }|d   |d   ||fS |d   | j                  d   |d   z  nd }|d   | j                  d   |d   z  nd }|d   |||d   fS )Nchannels_firstr   r         )r   r   )r   input_shapeheightwidths       r   compute_output_shapez!UpSampling2D.compute_output_shapeN   s    // q>- 		!{1~-  q>- 		!{1~- 
  NKNFEBB q>- 		!{1~-  q>- 		!{1~- 
  NFE;q>BBr   c                     | j                  || j                  d   | j                  d   | j                  | j                        S )Nr   r!   r   )_resize_imagesr   r   r   )r   inputss     r   callzUpSampling2D.callh   sE    ""IIaLIIaL,, # 
 	
r   c                 t    | j                   | j                  | j                  d}t        |          }i ||S )N)r   r   r   )r   r   r   r   
get_config)r   configbase_configr   s      r   r,   zUpSampling2D.get_configq   sB    II++!//

 g(*(+(((r   c                    |dvrt        d|       |dk(  rt        j                  |g d      }|dk(  r1t        j                  ||d      }t        j                  ||d      }nGt        j                  |      }|d   |z  |d   |z  f}t        j
                  j                  |||	      }|dk(  rt        j                  |g d
      }|S )a  Resizes the images contained in a 4D tensor.

        Args:
            x: Tensor or variable to resize.
            height_factor: Positive integer.
            width_factor: Positive integer.
            data_format: One of `"channels_first"`, `"channels_last"`.
            interpolation: A string, one of `"bicubic"`, `"bilinear"`,
            `"lanczos3"`, `"lanczos5"`, or `"nearest"`.

        Returns:
            A tensor.
        >   channels_lastr   z Invalid `data_format` argument: r   )r   r   r    r!   nearestr!   )axisr   r'   )r   r    r!   r   )
ValueErrorr   	transposerepeatshapeimageresize)r   xheight_factorwidth_factorr   r   r6   	new_shapes           r   r(   zUpSampling2D._resize_imagesz   s    * AA?}MNN**a.A I%

1m!4A

1l3A IIaLEa=(a<'I 		  I] KA**a.Ar   ))r   r   Nr1   )r1   )
__name__
__module____qualname____doc__r   r%   r*   r,   r(   __classcell__)r   s   @r   r
   r
   	   s.    8v <E,C4
)  0r   r
   N)	keras.srcr   r   keras.src.api_exportr   keras.src.layers.input_specr   keras.src.layers.layerr   keras.src.utilsr   r
   r   r   r   <module>rG      s;      - 1 ( / )*`5 ` +`r   