keras icon indicating copy to clipboard operation
keras copied to clipboard

keras outputs wrong pool_size in `keras.layers.AveragePooling1D`

Open cheyennee opened this issue 2 years ago • 4 comments

The pool_size of keras.layers.AveragePooling1D should be an integer. When I set an integer to keras.layers.AveragePooling1D, then outputs the pool_size of AveragePooling1D layer, I get a tuple. What a surprise😂

repo code:

import keras
layer = keras.layers.AveragePooling1D(pool_size=2)
print(layer.pool_size)

output:

(2,)

cheyennee avatar Dec 07 '23 04:12 cheyennee

Hi,

Thanks for reporting the issue.

AveragePooling1D is subclassing Basepooling class which is same for AveragePooling2D and AveragePooling3D.

Since AveragePooling2D and AveragePooling3D accepts the pool_size in int or tuple, the generic approach would be to return tuple.

Below is the Basepooling logic implementation, and it is not a bug.

https://github.com/keras-team/keras/blob/037ec9f5fc61a53c6e1f4c02b7bf1443429dcd45/keras/layers/pooling/base_pooling.py#L25-L31

sachinprasadhs avatar Dec 08 '23 00:12 sachinprasadhs

Hi, @sachinprasadhs . I think a distinction should be made between the two. I got this parameter to construct a new AveragePooling1D layer, but it doesn't support tuples as pool_size, which causes an error. IMO, If the output of pool_size is a tuple, I think a tuple value of pool_size should also work.

cheyennee avatar Dec 08 '23 02:12 cheyennee

For an int value, you can just use the below code.

import keras
layer = keras.layers.AveragePooling1D(pool_size=2)
print(layer.pool_size[0])

sachinprasadhs avatar Dec 08 '23 23:12 sachinprasadhs

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Dec 23 '23 01:12 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

github-actions[bot] avatar Apr 26 '24 01:04 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Apr 26 '24 01:04 google-ml-butler[bot]