0
votes

Image (50x50)

model =Sequential()
model.add(Conv2D(64,3,3,input_shape=(50,50,1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Conv2D(64,3,3,input_shape=(50,50,1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Flatten())
model.add(Dense(64))

model.add(Dense(5))
model.add(Activation('softmax'))



model.fit(X_train,y_train,epochs=5)

Error:Error when checking input: expected conv2d_6_input to have 4 dimensions, but got array with shape (270, 50, 50)

1
X_train = X_train.reshape(-1, 50, 50, 1) would solve the issue. - Mitiku
@Mitiku Thanks! - palash behra
Why is the input of the second Conv2D the same size as the first one? Shouldn't it be lower since you are doing a MaxPool and did not specify the 'Same' padding? - Salvador Molina

1 Answers

0
votes

Conv2D expects 4 dimensions because it expects a color channel (image can be greyscale, RGB, ect.)

You need to expand the dimensions to account for this channel using np.expand_dims