Keras error: 1 array expected

I got the following error when I tried to train the MLP model in keras (I am using keras version 1.2.2 )

Error checking model input: the list of Numpy arrays that you are switching to your model does not match the expected model. expected to see 1 array, but instead got the following list of 12859 arrays:

This is a summary of the model.

 ____________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ==================================================================================================== dense_1 (Dense) (None, 20) 4020 dense_input_1[0][0] ____________________________________________________________________________________________________ dense_2 (Dense) (None, 2) 42 dense_1[0][0] ==================================================================================================== Total params: 4,062 Trainable params: 4,062 Non-trainable params: 0 ____________________________________________________________________________________________________ None 

This is the first line of the model.

  model.add(Dense(20, input_shape=(200,), init='lecun_uniform', activation='tanh')) 

For training:

 model.fit(X,Y,nb_epoch=100,verbose=1) 

where X is a list of elements, and each element, in turn, is a list of 200 values.

Edit:

I also tried

 model.add(Dense(20, input_shape=(12859,200), init='lecun_uniform', activation='tanh')) 

but i get the same error

+5
source share
1 answer

Your mistake comes from the fact that your X for some reason was not converted to numpy.array . In this, your X considered as a list of strings, and this is the reason for your error message (that it was expecting a single entry instead of a list that contains several line items). Transformation:

 X = numpy.array(X) Y = numpy.array(Y) 

I would check the data loading process because something might go wrong.

UPDATE:

As mentioned in the comment - input_shape must be changed to input_dim .

UPDATE 2:

To save input_shape , you need to change it to input_shape=(200,) .

+4
source

Source: https://habr.com/ru/post/1265022/


All Articles