Neshy
Neshy

Reputation: 39

ValueError: Error when checking target: expected (keras Sequence model layer) to have n dimensions, but got array with shape

I have loaded images to train my model on recognizing one feature in those images.

When I train my model (model.fit(Xtrain,Ytrain)) I seem to get a value error on everyone of the layers. As if the input was both Xtrain then Ytrain...

ValueError: Error when checking target: expected batch_normalization_24 to have 4 dimensions, but got array with shape (1380, 2)

Image:

error message

Upvotes: 2

Views: 128

Answers (1)

aminrd
aminrd

Reputation: 5000

The shape of Keras's batch normalizer layer's output is the same as its input. Since you have only two labels, your final layer in a Sequential model should generate two outputs. You can consider adding a Dense layer like:

model.add(Dense(2), activation='relu')

I also recommend to check your model's architecture using print(model.summary()) and make sure that inputs and outputs match with your dataset and vice versa.

Upvotes: 2

Related Questions