Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input 0 of layer max_pooling2d is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [None, 4, 10, 8, 32]

When I try to define my model, I get the following error message:

Input 0 of layer max_pooling2d is incompatible with the layer: 
expected ndim=4, found ndim=5. 
Full shape received: [None, 4, 10, 8, 32].

The code I'm using is:

X_train = X_train.reshape(X_train.shape[0], 8, 10, 1)
X_test = X_test.reshape(len(X_test),10,8,1)
print(type(X_train),np.shape(X_train))



# CNN 
model = Sequential()
model.add(layers.Conv2D(32, (2, 2), activation='relu',
                    input_shape=(4,10, 8, 1),padding='same'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(layers.Dense(10, activation='softmax'))
like image 984
zahra zare Avatar asked Sep 02 '25 08:09

zahra zare


1 Answers

Input Layer is either expects data in the format of NHWC or NCHW.

N = Number of samples
H = Height of the Image
W = Width of the Image
C = Number of Channels

In most cases, N keeps varying so N is given as None. Based on your example, you can provide input shape and to convert between NHWC and NCHW you give input parameter as data_format=‘channel_first’ or data_format=‘channel_last’

like image 61
ATIF ADIB Avatar answered Sep 04 '25 23:09

ATIF ADIB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!