I can't understand what this error message is trying to tell me.
Looking at the summary of my model, I am looking at the last few layers .
But when I fit my model, I get the this:
I don't understand. If I read this closely, Keras seems to be saying, "I looked at the labels (targets) for the validation set, and sensibly, this made me think the last layer in your model should be shaped (None, 2). But, instead of actually getting a last layer shaped (None, 2) in the model, the layer consisted of an actual array. Which was of some other shape."
This makes no sense.
I think that I suspect that this error really should say, in general, is:
"ValueError: Error when checking model target: although dense_n has shape (x, y), the shape of the target, (a,b), in incompatible."
.
Does anyone care to agree or disagree? Thanks.
(There's a similar question here, but not very helpful.)
I'm not sure if the answer you expect is this, but...
First: I agree - the error message seems weird, it should talk about incompatibility between dense_24 and target array.
Now, to solve your problem, you should either reshape your target array or create a different Dense at the end to match your array.
About your target array, for a classification in two classes, it should be shaped as:
Dense(2,...)
at the end of your model, use Dense(1, activation='sigmoid')
.Why? Because your target data is shaped like (46000,1), meaning you have only one number for two classes. 0 is one class, 1 is another.
Keras is saying the network you constructed outputs arrays of length two, but the your training data contains data with shape (0,1). However, training data shape should match network output shape.
The shape (None, 2) simply means that the network accepts a batch with any number of elements that themselves are arrays of two elements (The first element is batch size in Keras shapes). So the correct input data shape would be (2,).
From the error message we see you have 4600 pieces of training data with shape (0, 1). This the reason for conflict. I suspect something goes wrong with reading the training data and you are not actually fitting with arrays of two elements, like you have intended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With