a
    Sic                     @   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                       s>   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f d|i| |d u r&t }|d u r2|}|| _t|dd| _tj|dddd| _t	|| _
t|| _tdd| _d S )	Nname   	pool_sizestridesT)
allow_zero   )ndim)super__init__r   image_data_formatpool_functionr   normalize_tupler
   r   normalize_paddingpaddingnormalize_data_formatdata_formatr   
input_spec)selfr   r
   r   r   r   r   kwargs	__class__ _/var/www/html/django/DPS/env/lib/python3.9/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 )Nchannels_last)   )r    r    r   )ksizer   r   r   )r   r
   r   r   r   upperr   convert_data_format)r   inputs
pool_shaper   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rt |d |d ||gS t |d |||d gS d S )Nchannels_firstr	      r    r   )	tfTensorShapeas_listr   r   conv_output_lengthr
   r   r   )r   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   configbase_configr   r   r   r2   p   s    
zPooling2D.get_config)r   NN)	__name__
__module____qualname____doc__r   r'   r1   r2   __classcell__r   r   r   r   r      s      r   )r;   tensorflow.compat.v2compatv2r*   kerasr   keras.engine.base_layerr   keras.engine.input_specr   keras.utilsr   r   r   r   r   r   <module>   s   