5
$\begingroup$

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?

$\endgroup$
  • 2
    $\begingroup$ Have you checked your model using model.summary()? $\endgroup$ – Ankit Seth Aug 14 '18 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 Aug 14 '18 at 14:12
7
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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