Keras: Exception: Input 0 is incompatible with layer dense_1: expected ndim=2, found ndim=4

Created on 14 May 2016  路  1Comment  路  Source: keras-team/keras

I was trying to build a simple sequential model processing dataset with 480*640 RGB images.
model.add(Convolution2D(64, 3, 3, border_mode="same", input_shape=(3, 480, 640), init="glorot_uniform"))
However, the exception throws as

Exception: Input 0 is incompatible with layer dense_1: expected ndim=2, found ndim=4

The shape of x_train is:

(200, 480, 640, 3)

200 is the number of samples, 480, 640 and 3 represent the 480*640 RGB value.

I am confused and look forward to have an answer.

Most helpful comment

Please read the docs first. Dense layer requires a 2d input.

model.add(Convolution2D(...)) # Output shape of convolution is 4d
model.add(Flatten()) # Flatten input into 2d
model.add(Dense(...)) # Dense layer require a 2d input

>All comments

Please read the docs first. Dense layer requires a 2d input.

model.add(Convolution2D(...)) # Output shape of convolution is 4d
model.add(Flatten()) # Flatten input into 2d
model.add(Dense(...)) # Dense layer require a 2d input
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nryant picture nryant  路  3Comments

anjishnu picture anjishnu  路  3Comments

amityaffliction picture amityaffliction  路  3Comments

braingineer picture braingineer  路  3Comments

fredtcaroli picture fredtcaroli  路  3Comments