Skip to content
Advertisement

Error related to the number of input tensors in Keras

I am inputting series of float32 grayscale images as a list with 16*16 shape to python and try do a regression task with labels inputted from Pandas data frame.

Here is the shape of images and df:

JavaScript

I used train_test_split from sklearn to split the data to train and test:

JavaScript

I am using the following model for doing the prediction, but model.fit returns error and does not run the training.

JavaScript

JavaScript

I also tested trainX = np.expand_dims(trainX, -1) before model.fit but it still gives another error. Can anyone help me to solve this?

JavaScript

Advertisement

Answer

Your next layers are simply Dense, so adding a Flatten layer on the top of your network does the job (no need to additional manipulate the input images)

JavaScript

Pay attention also to correctly manipulate your images…

Images are stores in a list of arrays. You have to transform the list into a single array of shapes (n_sample, 16, 16).

This can be done simply:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement