Home > Enterprise >  ValueError: Input 0 of layer "max_pooling1d" is incompatible with the layer: expected ndim
ValueError: Input 0 of layer "max_pooling1d" is incompatible with the layer: expected ndim

Time:12-05

I am building a CNN 1D model for binary classification and the file I used is csv file How can I solve this kind of error?....Thanks in advance

this is my code: enter image description here enter image description here

the error is: ValueError: Input 0 of layer "max_pooling1d" is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 51644, 29, 32) enter image description here

CodePudding user response:

Your data is 2D (a picture like), while you are trying to use a model that accepts 1D objects (sequences). You either need to use a model that accepts the type of data you want to work with, or you need to convert your data to fit your model.

CodePudding user response:

Change the input_shape from (train_shape[0], train_shape[1], 1) to (train_shape[1], 1). As you are using Conv1D, assuming you are working with a sequence data. So in this case train_shape[0] is the batch_size, train_shape[1] is the number of time-steps i.e, the sequence length and the last 1 is the number of features in each time-stamp.

The important thing is that, keras doesn't require you to input the batch_size, it is auto-defaulted to None and the input shape becomes (None, train_shape[1], 1) automatically, such that it can work with any batch sizes, so no need to input the first dimension. But if you want to input the batch size yourself, then use batch_input_shape instead of input_shape.

Also use softmax function in the output layer instead of sigmoid, as you have more than one neurons in the output layer.

  • Related