o
    M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 G dd deZdS )	z)Private base class for pooling 3D layers.    N)backend)Layer)	InputSpec)
conv_utilsc                       sD   e Zd ZdZ			d fdd	Zdd Zd	d
 Z fddZ  ZS )	Pooling3Da  Pooling layer for arbitrary pooling functions, for 3D inputs.

    This class only exists for code reuse. It will never be an exposed API.

    Args:
      pool_function: The pooling function to apply, e.g. `tf.nn.max_pool2d`.
      pool_size: An integer or tuple/list of 3 integers:
        (pool_depth, pool_height, pool_width)
        specifying the size of the pooling window.
        Can be a single integer to specify the same value for
        all spatial dimensions.
      strides: An integer or tuple/list of 3 integers,
        specifying the strides of the pooling operation.
        Can be a single integer to specify the same value for
        all spatial dimensions.
      padding: A string. The padding method, either 'valid' or 'same'.
        Case-insensitive.
      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, depth, height, width, channels)`
        while `channels_first` corresponds to
        inputs with shape `(batch, channels, depth, height, width)`.
      name: A string, the name of the layer.
    validchannels_lastNc                    s   t  jd	d|i| |d u rt }|d u r|}|| _t|dd| _tj|dddd| _t	|| _
t|| _tdd| _d S )
Nname   	pool_sizestridesT)Z
allow_zero   )ndim )super__init__r   Zimage_data_formatpool_functionr   Znormalize_tupler   r   Znormalize_paddingpaddingZnormalize_data_formatdata_formatr   Z
input_spec)selfr   r   r   r   r   r	   kwargs	__class__r   SD:\Projects\ConvertPro\env\Lib\site-packages\keras/layers/pooling/base_pooling3d.pyr   6   s   
zPooling3D.__init__c                 C   sd   d| j  d }d| j d }| jdkrt|d}| j|||| j d}| jdkr0t|d}|S )N)   channels_first)r      r
      r   )Zksizer   r   )r   r   r   r   r
   )r   r   r   tfZ	transposer   r   upper)r   ZinputsZ
pool_shaper   Zoutputsr   r   r   callN   s   

zPooling3D.callc                 C   s   t | }| jdkr|d }|d }|d }n|d }|d }|d }t|| jd | j| jd }t|| jd | j| jd }t|| jd | j| jd }| jdkret |d |d |||gS t |d ||||d gS )Nr   r   r
   r   r   r   )	r   ZTensorShapeas_listr   r   Zconv_output_lengthr   r   r   )r   Zinput_shapeZlen_dim1Zlen_dim2Zlen_dim3r   r   r   compute_output_shapec   s0   


zPooling3D.compute_output_shapec                    s<   | j | j| j| jd}t  }tt| t|  S )N)r   r   r   r   )	r   r   r   r   r   
get_configdictlistitems)r   configZbase_configr   r   r   r#      s   
zPooling3D.get_config)r   r   N)	__name__
__module____qualname____doc__r   r    r"   r#   __classcell__r   r   r   r   r      s     r   )r+   Ztensorflow.compat.v2compatv2r   Zkerasr   Zkeras.engine.base_layerr   Zkeras.engine.input_specr   Zkeras.utilsr   r   r   r   r   r   <module>   s   