from keras.models import Sequential from keras.layers import LSTM, Dense, Dropout from sklearn.metrics import precision_recall_fscore_support, roc_auc_score from keras.utils import np_utils from keras.callbacks import EarlyStopping data_dim = 41 timesteps = 20 num_classes = 10

expected input data shape: (batch_size, timesteps, data_dim)

model = Sequential()

returns a sequence of vectors of dimension 256

model.add(LSTM(256, return_sequences=True, input_shape=(timesteps, data_dim)))

return a single vector of dimension 128


apply softmax to output

model.add(Dense(num_classes, activation='softmax'))

compile the model for multi-class classification

model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

load fold1 for testing

train_x, train_y = load_folds([1,2,3,4,5,6])

load fold2 for validation

valid_x, valid_y = load_folds([9])

load fold3 for testing

test_x, test_y = load_folds([10])

a stopping function to stop training before we excessively overfit to the training set

earlystop = EarlyStopping(monitor='val_loss', patience=0, verbose=1, mode='auto') model.fit(train_x, train_y, batch_size=128, nb_epoch=10, callbacks=[earlystop], validation_data=(valid_x, valid_y))

this is my code when i run it i got error "ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)"

can someone help me to understand this and how can i solve it ?

  • $\begingroup$ did you ever figure out your problem? im running into this as well.. sorry would comment but not enough reputation $\endgroup$ – David Luong Aug 2 '18 at 14:16
  • $\begingroup$ yes.the error was raising because my dataset features were not extracted properly $\endgroup$ – Hiba Khanam Aug 8 '18 at 10:27

Your Answer

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

Browse other questions tagged or ask your own question.