Akshay
Akshay

Reputation: 41

Keras Multiple inputs - Expected to see 2 array(s), but instead got the following list of 1 arrays:

Following is the code to create model. Model has 2 input layers, 1 embedding, LSTM, attention, and dense layer. I am getting an error (image attached) when I am trying to execute model.fit with multiple inputs.

Not sure why? Please explain.

MAX_SEQUENCE_LENGTH = 20
# First input layer 
sequence_ip = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')

# Second input layer
time_Decay_ip = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='float32')

# Adding embedding layer
embedding_layer = Embedding(vocab_length, output_dim = 32, input_length=seq_length, trainable=True) 
embedded_sequences = embedding_layer(sequence_ip)

l_gru = LSTM(100, return_sequences=True)(embedded_sequences)
l_att = attention()([l_gru, time_Decay_ip])

preds = Dense(1, activation='softmax', trainable = True)(l_att)
model = Model([sequence_ip, time_Decay_ip], preds)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['acc'])

model.summary()
model.fit(x = [np.array(X_train), np.array(time_decay_tr)], y = np.array(Y_train), validation_data=(X_test, Y_test), nb_epoch=10, batch_size=9)

enter image description here"Error Message"

I checked shape and length of input list

Upvotes: 0

Views: 327

Answers (1)

Leo Gaunt
Leo Gaunt

Reputation: 693

I had this error when using keras, there are multiple ways to fix this:

You can either uninstall and reinstall the data you are using, Or you can uninstall and reinstall tensorflow.

You also need to check if your GPU is running trying to run CUDA (fron NVIDIA cards) if it is and you dont have a NVIDIA GPU use the CPU

Upvotes: 2

Related Questions