TensorFlow 1D model, wrong input shape for MaxPooling

I'm building a 1D model with TensorFlow for audio but I have a problem with the input shape during the second MaxPool1D in the model.

The problem is here, after this Pooling:

x = Convolution1D(32, 3, activation=relu, padding='valid')(x)
x = MaxPool1D(4)(x)

I get this error:

ValueError: Negative dimension size caused by subtracting 4 from 1 for 'max_pooling1d_5/MaxPool' (op: 'MaxPool') with input shapes: [?,1,1,32].

I tried to reshape x (which is a tensor) but I don't think I'm going in the right way.

In this same model, before that, I have a couple convolutional layers and a maxpooling that are working proporly.

Anyone have suggestions? Thanks

1 answer

  • answered 2018-11-14 14:38 A Kruger

    The number of steps in the input to the MaxPool1D layer is smaller than the pool size.

    In the error, it says ...input shapes: [?,1,1,32], which means the output from the Convolution1D layer has shape [1,32]. It needs to be at least 4 steps to be used as input to the MaxPool1D(4) layer, so have a minimum size of [4,32].

    You can continue walking this back. For example, the Convolution1D layer will decrease the step size by kernel_size-1=2. This means the input to the Convolution1D layer needs to have at least 4+2=6 steps, meaning a shape of at least [6,?]. Continuing up to the input layer, you'll find the input size is too small.

    You'll need to change the architecture to allow the input size, or, if applicable, change the input size.