How does average pooling function work in TensorFlow?
Hi @ahmoosavi 

With padding = "same", pool_size =(4, 4) and stride = (4, 4) , the tensor would look like this

```
  0   0   0   0    0   0   0  0
  0   1   2   3    4   5   0  0
  0   6   7   8    9   10  0  0
  0   0   0   0    0   0   0  0
```
Padding = "same" tries to pad evenly left and right, but if the amount of columns to be added is odd, it will add the extra column to the right, as is the case in this example (the same logic applies vertically: there may be an extra row of zeros at the bottom).

The output shape when using the "same" padding option is: 
```
output_shape = math.floor((input_shape - 1) / strides) + 1
```
The logic would be 
(1+2+3+0+6+7+8)/6 = 27/6 =4.5
(4+5+9+10)/4 = 28/4 = 7

Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60509">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60509">No</a>

Let us assume a tensor like this:

```
x = tf.constant([[1., 2., 3.],
                  [4., 5., 6.],
                  [7., 8., 9.]])
```

To apply the average pooling function, I will do this:

```
x = tf.reshape(x, [1, 3, 3, 1])
avg_pool_2d = tf.keras.layers.AveragePooling2D(pool_size=(2, 2),strides=(2, 2), padding='same')
avg_pool_2d(x)
```

The result is:

```
<tf.Tensor: shape=(1, 2, 2, 1), dtype=float32, numpy=
array([[[[3. ],
         [4.5]],
        [[7.5],
         [9. ]]]], dtype=float32)>
```

I can follow the logic above:

```
(1+2+4+5)/4 = 3
(3+6)/2 = 4.5
(7+8)/2 = 7.5
(9/1) = 9
```

**I think the logic is:**  The pooling filter is usually situated inside the tensor to perform the pooling operator. But when the entire filter does not situate inside the tensor (see the below figure for an example), we need to specify the number of elements of the filter that are situated inside the tensor (a). The following figure illustrates the logic for a 4 by 3 tensor, with pooling filter and stride sizes of 2 by 2, and padding the same.

![image](https://user-images.githubusercontent.com/82632526/236491612-8b6b6fee-414a-4dd6-ba7d-98c77713a7c9.png)

However, it is not always like this. For example, suppose the following tensor:

```
y = tf.constant([[1., 2., 3., 4., 5.],
                         [6., 7., 8., 9., 10.]])
```

Then, I do this:

```
y = tf.reshape(y, [1, 2, 5, 1])
avg_pool_2d = tf.keras.layers.AveragePooling2D(pool_size=(4, 4),strides=(4, 4), padding='same')
avg_pool_2d(y)
```

The result is like this:

```
    <tf.Tensor: shape=(1, 1, 2, 1), dtype=float32, numpy=
array([[[[4.5 ],
         [7.]]]], dtype=float32)>
```

If I wanted to follow the logic for the first example, I expected the result to be like this:

```
(1+2+3+4+6+7+8+9)/8 = 5
(5+10)/2 = 7.5
```

I am using TensorFlow 2.8.0. What mistake am I making?