0
$\begingroup$

I am trying to fit a keras classifier on a data matrix X_train

dummy_y = np_utils.to_categorical(y_train)
dummy_y_val = np_utils.to_categorical(y_val)

def baseline_model(optimizer='rmsprop', init='normal', dropout_rate =0.0):
    model = Sequential()
    model.add(Dense(100, input_dim = X_train.shape[1], activation='relu', init=init))
    model.add(Dropout(dropout_rate))
    model.add(Dense(50, activation = 'relu', init = init))
    model.add(Dropout(dropout_rate))
    model.add(Dense(15, activation = 'sigmoid', init = init))
    model.compile(loss = 'binary_crossentropy', optimizer = optimizer, metrics =['accuracy'])
    return model

   estimator = KerasClassifier(build_fn=baseline_model, nb_epoch=200, batch_size=5, verbose=0)
   model = baseline_model()

model.fit(X_train, dummy_y, batch_size=32,  verbose=1, callbacks=None, \
     validation_data=(X_val, dummy_y_val), shuffle=True, class_weight=None, \
    sample_weight=None, initial_epoch=0)

That's what I get as an error :

Train on 582 samples, validate on 290 samples Epoch 1/10

ValueErrorTraceback (most recent call last) in () 1 model = baseline_model() ----> 2 model.fit(X_train, dummy_y, batch_size=32, verbose=1,

....

ValueError: Cannot feed value of shape (582, 32) for Tensor u'dense_input_28:0', which has shape '(?, 18760)'

NOTE : X_train.shape = (580,18760) and y_train has 15 classes

$\endgroup$
3
$\begingroup$

The problem was : X_train and y_train were not numpy array. I transformed them to numpy arrays and it solved the problem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.