Will Buxton
Will Buxton

Reputation: 53

ValueError: Error when checking model target: expected dense_4 to have shape (None, 4) but got array with shape (13252, 1)

Hi does anyone have any ideas why this error is happening? Here is the error

ValueError: Error when checking model target: expected dense_4 to have   shape (None, 4) but got array with shape (13252, 1)

And here is the code:

from keras.models import Sequential
from keras.layers import *

model = Sequential()
model.add(Cropping2D(cropping=((0,0), (50,20)), input_shape=(160 ,320, 3))) #(None, 90, 320, 3)
model.add(Lambda(lambda x: x/127.5 - 1.)) 
model.add(Convolution2D(32, 3, 3,)) #(None, 88, 318, 32)
model.add(Activation('relu'))
model.add(Convolution2D(32, 3, 3)) #(None, 86, 316, 32)
model.add(Activation('relu'))
model.add(Flatten()) #(None, 869632)
model.add(Dense(128)) #(None, 128)
model.add(Activation('relu'))
model.add(Dense(4)) #(None, 4)
print(model.summary())

model.compile(loss='mse', optimizer='adam')
model.fit(X, y, validation_split=0.2, batch_size=32, nb_epoch=3, verbose=1)

The input shape is (X):

(13252, 160, 320, 3)

And (y):

(13252,)

Upvotes: 3

Views: 1750

Answers (1)

lejlot
lejlot

Reputation: 66775

Since your network has four outputs, your y has to be N x 4 matrix, not a vector of length N. Either change y, or last layer to be Dense(1)

Upvotes: 7

Related Questions