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 2D 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 )	Pooling2Da  Pooling layer for arbitrary pooling functions, for 2D inputs (e.g. images).

    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 2 integers:
        (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 2 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, height, width, channels)` while `channels_first` corresponds to
        inputs with shape `(batch, channels, height, width)`.
      name: A string, the name of the layer.
    validNc                    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_pooling2d.pyr   5   s   
zPooling2D.__init__c              	   C   sd   | j dkrd| j d }d| j d }n
d| j }d| j }| j|||| j t| j dd}|S )NZchannels_last)   )r   r   r   )Zksizer   r   r   )r   r
   r   r   r   upperr   Zconvert_data_format)r   ZinputsZ
pool_shaper   Zoutputsr   r   r   callM   s   


zPooling2D.callc                 C   s   t | }| jdkr|d }|d }n|d }|d }t|| jd | j| jd }t|| jd | j| jd }| jdkrMt |d |d ||gS t |d |||d gS )NZchannels_firstr	      r   r   )	tfZTensorShapeas_listr   r   Zconv_output_lengthr
   r   r   )r   Zinput_shaperowscolsr   r   r   compute_output_shape]   s   


zPooling2D.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"   p   s   
zPooling2D.get_config)r   NN)	__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   