Mr.Awan
Mr.Awan

Reputation: 43

ValueError: Input 0 is incompatible with layer conv2_1: expected ndim=4, found ndim=3

I'm new to Deep Learning. I have randomly generated datasets with following shape (5,4,4). It's something like

[[[1 2 3 4] [4 5 6 7] [7 8 9 10]]]

I don't know why is it giving problem related to dimensions

My Keras code is given below

X_train=np.random.randint(0,100,size=(5,4,4))
Y_train=np.random.rand(5,1)
X_valid=np.random.randint(0,100,size=(2,4,4)
Y_valid=np.random.rand(2,1)

def create_model():
    nb_filters=2
    nb_conv=2
    model=Sequential()
    model.add(Convolution2d(nb_filters,nb_conv,padding='same',input_shape=(4,4)
    model.add(Activation('relu'))
    ****Other layers****
    enter code here
    model.add(Dense(1)
    model.add(Activation('linear')
    model.compile(loss='mean_squared_error', optimizer=Adadelta())
    return model
model=create_model()
model.fit(X_train,Y_train, batch_size=2,nb_epoch=50,verbos=1, validation_data=(X_valid,Y_valid)

Upvotes: 0

Views: 67

Answers (1)

Mikhail Berlinkov
Mikhail Berlinkov

Reputation: 1624

Your input data is missing the channel dimension (see docs)

Upvotes: 2

Related Questions