Error when checking input: expected dense_Dense1_input to have x dimension(s). but got array with shape y,z

Your error comes from a mismatch of the size of the training and test data from one hand on the other hand by what is defined as the input of your model

model.add(tf.layers.dense({units: 1, inputShape: [5, 5] }));

The inputShape is your input dimension. Here it is 5, because each features is an array of size 5.

model.predict(tf.tensor(5))

Also to test your model, your data should have the same shape as when your are training your model. Your model cannot predict anything with tf.tensor(5). Because your training data and your test data size do not match. Consider this test data instead tf.tensor2d([5, 1, 2, 3, 4], [1, 5])

Here is a working snipet

Leave a Comment