Skip to content Skip to sidebar Skip to footer

Valueerror: Negative Dimension Size Caused By Subtracting 2 From 1 For Maxpool1d With Input Shapes: [?,1,1,128]. Full Code,output & Error In The Post:

I have an error while making the following CNN model: features_train = np.reshape(features_train, (2363,2,-1)) features_test = np.reshape(features_test, (591,2,-1)) features_train

Solution 1:

MaxPooling1D downsizes the model by 2, so the output of the first Pooling Layer is 1, then you have more Pooling layers which won't work, as it cannot be downsized by 2 anymore
Therefore, you cannot have more than 1 Pooling Layer in your model
Also, I would not suggest to use a MaxPooling1D layers on such a small input
Another thing, You have 1 unit on the final layer and a softmax activation function which makes no sense. Using softmax on the final layer with one unit will always return a value of 1
So, I think you want to use sigmoid and not softmax
Your model should be like this,

model_2 = Sequential()

model_2.add(Conv1D(64, kernel_size=1, activation='relu', input_shape=(2,1)))
model_2.add(BatchNormalization())

model_2.add(Conv1D(32, kernel_size=1, activation='relu'))
model_2.add(BatchNormalization())

model_2.add(Flatten())

model_2.add(Dense(10,kernel_initializer="uniform",activation='relu'))
model_2.add(Dense(1,kernel_initializer="uniform",activation='sigmoid'))

Post a Comment for "Valueerror: Negative Dimension Size Caused By Subtracting 2 From 1 For Maxpool1d With Input Shapes: [?,1,1,128]. Full Code,output & Error In The Post:"