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.UpSampling3Dc                       sF   e Zd ZdZd fdd	Zdd Zdd	 Z fd
dZdd Z  Z	S )UpSampling3Da  Upsampling layer for 3D inputs.

    Repeats the 1st, 2nd and 3rd dimensions
    of the data by `size[0]`, `size[1]` and `size[2]` respectively.

    Example:

    >>> input_shape = (2, 1, 2, 1, 3)
    >>> x = np.ones(input_shape)
    >>> y = keras.layers.UpSampling3D(size=(2, 2, 2))(x)
    >>> y.shape
    (2, 2, 4, 2, 3)

    Args:
        size: Int, or tuple of 3 integers.
            The upsampling factors for dim1, dim2 and dim3.
        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, spatial_dim1, spatial_dim2, spatial_dim3, channels)`
            while `"channels_first"` corresponds to inputs with shape
            `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.
            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"`.

    Input shape:
        5D tensor with shape:
        - If `data_format` is `"channels_last"`:
            `(batch_size, dim1, dim2, dim3, channels)`
        - If `data_format` is `"channels_first"`:
            `(batch_size, channels, dim1, dim2, dim3)`

    Output shape:
        5D tensor with shape:
        - If `data_format` is `"channels_last"`:
            `(batch_size, upsampled_dim1, upsampled_dim2, upsampled_dim3,
            channels)`
        - If `data_format` is `"channels_first"`:
            `(batch_size, channels, upsampled_dim1, upsampled_dim2,
            upsampled_dim3)`
       r
   r
   Nc                    s>   t  jdi | t|| _t|dd| _tdd| _	d S )N   size   )ndim )
super__init__r   standardize_data_formatdata_formatr   standardize_tupler   r   
input_spec)selfr   r   kwargs	__class__r   c/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/reshaping/up_sampling3d.pyr   8   s   zUpSampling3D.__init__c                 C   s  | j dkrC|d d ur| jd |d  nd }|d d ur%| jd |d  nd }|d d ur6| jd |d  nd }|d |d |||fS |d d urR| jd |d  nd }|d d urc| jd |d  nd }|d d urt| jd |d  nd }|d ||||d fS )Nchannels_firstr
   r   r         )r   r   )r   input_shapedim1dim2dim3r   r   r   compute_output_shape>   s6   
z!UpSampling3D.compute_output_shapec                 C   s&   |  || jd | jd | jd | jS )Nr   r   r
   )_resize_volumesr   r   )r   inputsr   r   r   callb   s   zUpSampling3D.callc                    s$   | j | jd}t  }i ||S )N)r   r   )r   r   r   
get_config)r   configbase_configr   r   r   r&   g   s   
zUpSampling3D.get_configc                 C   s   |dkrt j||dd}t j||dd}t j||dd}|S |dkr<t j||dd}t j||dd}t j||dd}|S td| )	ak  Resizes the volume contained in a 5D tensor.

        Args:
            x: Tensor or variable to resize.
            depth_factor: Positive integer.
            height_factor: Positive integer.
            width_factor: Positive integer.
            data_format: One of `"channels_first"`, `"channels_last"`.

        Returns:
            Resized tensor.
        r   r
   )axisr   r   channels_lastr   zInvalid data_format: )r   repeat
ValueError)r   xdepth_factorheight_factorwidth_factorr   outputr   r   r   r#   l   s   zUpSampling3D._resize_volumes)r	   N)
__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    