
    6bi                     `    S r SSKJs  Jr  SSKJr  SSKJr  SSK	J
r
  SSKJr   " S S\5      rg)	z)Private base class for pooling 2D layers.    N)backend)Layer)	InputSpec)
conv_utilsc                   N   ^  \ rS rSrSr   SU 4S jjrS rS rU 4S jrSr	U =r
$ )		Pooling2D   a<  Pooling layer for arbitrary pooling functions, for 2D data (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.
c                 j  > [         TU ]  " S	SU0UD6  Uc  [        R                  " 5       nUc  UnXl        [
        R                  " USS5      U l        [
        R                  " USSSS9U l        [
        R                  " U5      U l
        [
        R                  " U5      U l        [        SS9U l        g )
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__s	           d/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/pooling/base_pooling2d.pyr   Pooling2D.__init__5   s     	-d-f-!335K?G*#33Iq+N!11Q	d
 "33G<%;;KH#+    c           
      @   U R                   S:X  a%  SU R                  -   S-   nSU R                  -   S-   nOSU R                  -   nSU R                  -   nU R                  UUUU R                  R                  5       [        R                  " U R                   S5      S9nU$ )Nchannels_last)   )r%   r%   r   )ksizer   r   r   )r   r   r   r   r   upperr   convert_data_format)r   inputs
pool_shaper   outputss        r    callPooling2D.callM   s    ..5JT\\)D0G$..0Jt||+G$$LL&&("66t7G7GK % 
 r"   c                     [         R                  " U5      R                  5       nU R                  S:X  a  US   nUS   nO
US   nUS   n[        R
                  " X R                  S   U R                  U R                  S   5      n[        R
                  " X0R                  S   U R                  U R                  S   5      nU R                  S:X  a  [         R                  " US   US   X#/5      $ [         R                  " US   X#US   /5      $ )Nchannels_firstr      r%   r   )	tfTensorShapeas_listr   r   conv_output_lengthr   r   r   )r   input_shaperowscolss       r    compute_output_shapePooling2D.compute_output_shape]   s    nn[199;//q>Dq>Dq>Dq>D,,..#T\\4<<?
 ,,..#T\\4<<?
 //>>;q>;q>4"NOO>>;q>4{1~"NOOr"   c                    > U R                   U R                  U R                  U R                  S.n[        TU ]  5       n[        [        UR                  5       5      [        UR                  5       5      -   5      $ )N)r   r   r   r   )	r   r   r   r   r   
get_configdictlistitems)r   configbase_configr   s      r    r;   Pooling2D.get_configp   s`    ||||++	
 g(*D**,-V\\^0DDEEr"   )r   r   r   r   r   r   )validNN)__name__
__module____qualname____firstlineno____doc__r   r,   r8   r;   __static_attributes____classcell__)r   s   @r    r   r      s/    > ,0 P&F Fr"   r   )rG   tensorflow.compat.v2compatv2r1   tf_keras.srcr   tf_keras.src.engine.base_layerr   tf_keras.src.engine.input_specr   tf_keras.src.utilsr   r   r   r"   r    <module>rQ      s.    0 " !   0 4 )^F ^Fr"   