Search code examples
python-3.xmachine-learningkerastensormax-pooling

Why does keras.backend.pool3d requires tensor_in to be 5-dimensional?


I have the following code

from tensorflow import keras
from keras import backend as K

pool_size = (2,2,2)
strides = (2,2,2)

yt = K.zeros(shape=(10,10,10))

result = keras.backend.pool3d(yt, pool_size, strides, pool_mode="avg")

When I try to run the code it says

.. InvalidArgumentError: tensor_in must be 5-dimensional [Op:AvgPool3D] name: AvgPool3D/

I seem to not like the dimension of yt. But I want to max pool in 3d image whose dimension is 3x3x3. What should the other dimension be?


Solution

    • batch size
    • channels

    As every convolution-like operation in Keras, these dimensions are required.

    • Using "channels_last" (default): (batch, size1, size2, size3, channels)
    • Using "channels_first": (batch, channels, size1, size2, size3)

    So:

    yt = K.zeros(shape=(1,10,10,10,1))