1

It seems that Keras lacks documentation regarding functional API but I might be getting it all wrong.

I have multiple independent inputs and I want to predict an output for each input. Here's my code so far:

 hour = Input(shape=(1,1), name='hour')
 hour_output = LSTM(1, name='hour_output')(hour)

 port = Input(shape=(1,1), name='port')
 port_output = LSTM(1, name='port_output')(port)

 model = Model(inputs=[hour, port], outputs = [hour_output, port_output])

 model.compile(loss="mean_squared_error", optimizer="adam", metrics=['accuracy'])
 model.fit(trainX, trainY, epochs=10 batch_size=1, verbose=2, shuffle=False)

Error I get for this:

ValueError: No data provided for "hour_output". Need data for each key in: ['hour_output', 'port_output']

I also had a hard time getting the right input for this, so I ended up using dictionary with example structure:{'hour': array([[[0]], [[1]], [[3]]]) }. I don't like that (using dict) either.

Note that I have more inputs to use and for this to make sense, but now I am just trying to make the model work.

1 Answer 1

1

In your model.fit you need to provide a list of inputs with length = 2, since you define two inputs in your Model.

Split your training data in train_hour and train_port and call fit like:

model.fit([train_X_hour, train_X_port], [train_Y_hour, train_Y_port] epochs=10, batch_size=1, verbose=2, shuffle=False)
Sign up to request clarification or add additional context in comments.

6 Comments

According to the docs input can be: Numpy array of training data, or list of Numpy arrays if the model has multiple inputs. If all inputs in the model are named, you can also pass a dictionary mapping input names to Numpy arrays. meaning that your approach is the same as my dictionary. However, I've tried that and it really doesn't make a change.
But yes, I guess that answers my other question/complaint about not using dictionary :)
Well, you said you did not like the dictionary option, so I gave you the other option. You have to use one of the two - maybe I'm not really understanding what you are asking?
Yes, that's fine, thank you. The main question here is about running the training, I still can't pass the error.
You mean that even by passing the inputs as a list it throws you that ValueError?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.