o
    2h                     @   sd   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 )    )backend)ops)keras_export)	InputSpec)Layer)argument_validationzkeras.layers.UpSampling2Dc                       sL   e Zd ZdZ	d fdd	Zdd Zd	d
 Z fddZ	dddZ  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)`
       r
   Nnearestc                    sH   t  jdi | t|| _t|dd| _| | _	t
dd| _d S )Nr
   size   )ndim )super__init__r   standardize_data_formatdata_formatr   standardize_tupler   lowerinterpolationr   
input_spec)selfr   r   r   kwargs	__class__r   c/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/reshaping/up_sampling2d.pyr   E   s
   
zUpSampling2D.__init__c                 C   s   | j dkr1|d d ur| jd |d  nd }|d d ur%| jd |d  nd }|d |d ||fS |d d ur@| jd |d  nd }|d d urQ| jd |d  nd }|d |||d fS )Nchannels_firstr
   r         )r   r   )r   input_shapeheightwidthr   r   r   compute_output_shapeN   s&   
z!UpSampling2D.compute_output_shapec                 C   s$   | j || jd | jd | j| jdS )Nr   r   )r   )_resize_imagesr   r   r   )r   inputsr   r   r   callh   s   zUpSampling2D.callc                    s(   | j | j| jd}t  }i ||S )N)r   r   r   )r   r   r   r   
get_config)r   configbase_configr   r   r   r'   q   s   
zUpSampling2D.get_configc                 C   s   |dvrt d| |dkrt|g d}|dkr,tj||dd}tj||dd}nt|}|d | |d | f}tjj||d	|d
}|dkrSt|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   r   r   )axisr
   r*   )r   r   )r   r   r   r
   )
ValueErrorr   	transposerepeatshapeimageresize)r   xheight_factorwidth_factorr   r   r/   	new_shaper   r   r   r$   z   s(   
	

zUpSampling2D._resize_images)r	   Nr   )r   )
__name__
__module____qualname____doc__r   r#   r&   r'   r$   __classcell__r   r   r   r   r   	   s    ;		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   r   <module>   s    