2

I get the following error:

ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 6 arrays but instead got the following list of 3 arrays: [array([[ 0,  0,  0, ..., 18, 12,  1],
       [ 0,  0,  0, ..., 18, 11,  1],
       [ 0,  0,  0, ..., 18,  9,  1],
       ...,
       [ 0,  0,  0, ..., 18, 15,  1],
       [ 0,  0,  0, ..., 18,  9,  ...

in my keras model.

I think the model is mistaking something?

This happens when I feed input to my model. The same input works perfectly well in another program.

2 Answers 2

4

It's impossible to diagnose your exact problem without more information.

I usually specify the input_shape parameter of the first layer based on my training data X.

e.g.

model = Sequential()
model.add(Dense(32, input_shape=X.shape[0]))

I think you'll want X to look something like this:

   [
    [[ 0,  0,  0, ..., 18, 11,  1]],
    [[ 0,  0,  0, ..., 18,  9,  1]],
   ....
   ]

So you could try reshaping it with the following line:

X = np.array([[sample] for sample in X])
Sign up to request clarification or add additional context in comments.

6 Comments

again, get the same error ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 6 arrays but instead got the following list of 3 arrays: [array([[[ 0, 0, 0, ..., 18, 12, 1]], [[ 0, 0, 0, ..., 18, 11, 1]], [[ 0, 0, 0, ..., 18, 9, 1]], ..., [[ 0, 0, 0, ..., 18, 15, 1]], [[ 0, 0, 0, ....
Well you can see from the error code that your attempting to feed in a list of three arrays. You need to make sure your training data looks like the X I showed above.
I am training it just the same way as in the official example code of keras. My Input data is of the shape (10000, 68). I can't see where and how 6 arrays are needed. No layer has shape of taking 6 arrays as input. How did you come up with the suggestion ?
I'm not going to debug the 300 line code you linked to. If you want more feedback you'll have to find relevant code to include in your question.
no i am not asking to debug. i am just asking how did you guess the initial fix? 6 arrays is needed, 3 are there...in your fix for each sample a new array...I guess understanding it will help me in the debugging. Thanks.
|
0

The problem really comes from giving the wrong input to the network.

In my case the problem was that my custom image generator was passing the entire dataset as input rather than a certain pair of image-label. This is because I thought that generator.flow(x,y, batch_size) of Keras already has a yield structure inside, however the correct generator structure should be as follows(with a separate yield):

def generator(batch_size):

(images, labels) = utils.get_data(1000) # gets 1000 samples from dataset
labels = to_categorical(labels, 2)

generator = ImageDataGenerator(featurewise_center=True,
                 featurewise_std_normalization=True,
                 rotation_range=90.,
                 width_shift_range=0.1,
                 height_shift_range=0.1,
                 zoom_range=0.2)

generator.fit(images)

gen = generator.flow(images, labels, batch_size=32)

while 1:
    x_batch, y_batch = gen.next()
    yield ([x_batch, y_batch])

I realize the question is old but it might save some time for someone to find the issue.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.