My data consists of 2-dimensional arrays with shape (2,3). The whole dataset (emp) consists of 12 items (I know that it is too small of a number for an NN training, but it is just a test), so it has shape (12,2,3)

truevals has shape (12,)

When I try to add Keras layer:

model = Sequential()
model.add(Dense(4, input_shape=(2,3), activation='tanh'))
model.add(Dense(1, activation='sigmoid'))
model.compile(SGD(lr=0.5), 'binary_crossentropy', metrics=['accuracy'])
model.fit(emp, truevals, epochs=200)

and then when I fit the model I get the exception:

Error when checking target: expected dense_30 to have 3 dimensions, but got array with shape (12, 1).

What am I doing wrong?

  • 2
    $\begingroup$ Have you checked your model using model.summary()? $\endgroup$
    – Ankit Seth
    Commented Aug 14, 2018 at 7:31
  • $\begingroup$ Strong +1 to looking at and sharing the results of the model summary. It’s invaluable for diagnosing shape problems. $\endgroup$
    – kbrose
    Commented Aug 14, 2018 at 14:12

1 Answer 1


Dense layers doesn't reduce dimensions of inputs, so if you provide a (12,2,3) input, it expects a (12,2,1) output (for your case).

If you want to make it work, you should flatten your input (or output of first layer) and provide a (12,1) output.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.