Keras Functional API Multi Input Layer
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
How do I define a multi input layer using Keras Functional API? Below is an example of the neural network I want to build. There are three input nodes. I want each node to be a 1 dimensional numpy array of different lengths.
Here's what I have so far. Basically I want to define an input layer with multiple input tensors.
from keras.layers import Input, Dense, Dropout, concatenate
from keras.models import Model
x1 = Input(shape =(10,))
x2 = Input(shape =(12,))
x3 = Input(shape =(15,))
input_layer = concatenate([x1,x2,x3])
hidden_layer = Dense(units=4, activation='relu')(input_layer)
prediction = Dense(1, activation='linear')(hidden_layer)
model = Model(inputs=input_layer,outputs=prediction)
model.summary()
The code gives the error.
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("x1_1:0", shape=(?, 10), dtype=float32) at layer "x1". The following previous layers were accessed without issue:
Later when I fit the model I will pass in a list of 1D numpy arrays with the corresponding lengths.
python machine-learning keras
add a comment |
How do I define a multi input layer using Keras Functional API? Below is an example of the neural network I want to build. There are three input nodes. I want each node to be a 1 dimensional numpy array of different lengths.
Here's what I have so far. Basically I want to define an input layer with multiple input tensors.
from keras.layers import Input, Dense, Dropout, concatenate
from keras.models import Model
x1 = Input(shape =(10,))
x2 = Input(shape =(12,))
x3 = Input(shape =(15,))
input_layer = concatenate([x1,x2,x3])
hidden_layer = Dense(units=4, activation='relu')(input_layer)
prediction = Dense(1, activation='linear')(hidden_layer)
model = Model(inputs=input_layer,outputs=prediction)
model.summary()
The code gives the error.
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("x1_1:0", shape=(?, 10), dtype=float32) at layer "x1". The following previous layers were accessed without issue:
Later when I fit the model I will pass in a list of 1D numpy arrays with the corresponding lengths.
python machine-learning keras
1
The funcional API guide describes exactly how to make multiple input models keras.io/getting-started/functional-api-guide your problem is that you have to give the inputs (x1, x2, x3), not the layer after that.
– Matias Valdenegro
Jan 3 at 21:16
add a comment |
How do I define a multi input layer using Keras Functional API? Below is an example of the neural network I want to build. There are three input nodes. I want each node to be a 1 dimensional numpy array of different lengths.
Here's what I have so far. Basically I want to define an input layer with multiple input tensors.
from keras.layers import Input, Dense, Dropout, concatenate
from keras.models import Model
x1 = Input(shape =(10,))
x2 = Input(shape =(12,))
x3 = Input(shape =(15,))
input_layer = concatenate([x1,x2,x3])
hidden_layer = Dense(units=4, activation='relu')(input_layer)
prediction = Dense(1, activation='linear')(hidden_layer)
model = Model(inputs=input_layer,outputs=prediction)
model.summary()
The code gives the error.
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("x1_1:0", shape=(?, 10), dtype=float32) at layer "x1". The following previous layers were accessed without issue:
Later when I fit the model I will pass in a list of 1D numpy arrays with the corresponding lengths.
python machine-learning keras
How do I define a multi input layer using Keras Functional API? Below is an example of the neural network I want to build. There are three input nodes. I want each node to be a 1 dimensional numpy array of different lengths.
Here's what I have so far. Basically I want to define an input layer with multiple input tensors.
from keras.layers import Input, Dense, Dropout, concatenate
from keras.models import Model
x1 = Input(shape =(10,))
x2 = Input(shape =(12,))
x3 = Input(shape =(15,))
input_layer = concatenate([x1,x2,x3])
hidden_layer = Dense(units=4, activation='relu')(input_layer)
prediction = Dense(1, activation='linear')(hidden_layer)
model = Model(inputs=input_layer,outputs=prediction)
model.summary()
The code gives the error.
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("x1_1:0", shape=(?, 10), dtype=float32) at layer "x1". The following previous layers were accessed without issue:
Later when I fit the model I will pass in a list of 1D numpy arrays with the corresponding lengths.
python machine-learning keras
python machine-learning keras
asked Jan 3 at 21:11
cooldood3490cooldood3490
1,01422850
1,01422850
1
The funcional API guide describes exactly how to make multiple input models keras.io/getting-started/functional-api-guide your problem is that you have to give the inputs (x1, x2, x3), not the layer after that.
– Matias Valdenegro
Jan 3 at 21:16
add a comment |
1
The funcional API guide describes exactly how to make multiple input models keras.io/getting-started/functional-api-guide your problem is that you have to give the inputs (x1, x2, x3), not the layer after that.
– Matias Valdenegro
Jan 3 at 21:16
1
1
The funcional API guide describes exactly how to make multiple input models keras.io/getting-started/functional-api-guide your problem is that you have to give the inputs (x1, x2, x3), not the layer after that.
– Matias Valdenegro
Jan 3 at 21:16
The funcional API guide describes exactly how to make multiple input models keras.io/getting-started/functional-api-guide your problem is that you have to give the inputs (x1, x2, x3), not the layer after that.
– Matias Valdenegro
Jan 3 at 21:16
add a comment |
2 Answers
2
active
oldest
votes
The inputs must be your Input()
layers:
model = Model(inputs=[x1, x2, x3],outputs=prediction)
add a comment |
Change
model = Model(inputs=input_layer,outputs=prediction)
to
model = Model(inputs=[x1, x2, x3],outputs=prediction)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029867%2fkeras-functional-api-multi-input-layer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The inputs must be your Input()
layers:
model = Model(inputs=[x1, x2, x3],outputs=prediction)
add a comment |
The inputs must be your Input()
layers:
model = Model(inputs=[x1, x2, x3],outputs=prediction)
add a comment |
The inputs must be your Input()
layers:
model = Model(inputs=[x1, x2, x3],outputs=prediction)
The inputs must be your Input()
layers:
model = Model(inputs=[x1, x2, x3],outputs=prediction)
answered Jan 3 at 21:18
PrimusaPrimusa
8,04021032
8,04021032
add a comment |
add a comment |
Change
model = Model(inputs=input_layer,outputs=prediction)
to
model = Model(inputs=[x1, x2, x3],outputs=prediction)
add a comment |
Change
model = Model(inputs=input_layer,outputs=prediction)
to
model = Model(inputs=[x1, x2, x3],outputs=prediction)
add a comment |
Change
model = Model(inputs=input_layer,outputs=prediction)
to
model = Model(inputs=[x1, x2, x3],outputs=prediction)
Change
model = Model(inputs=input_layer,outputs=prediction)
to
model = Model(inputs=[x1, x2, x3],outputs=prediction)
answered Jan 3 at 21:19
Luke DeLucciaLuke DeLuccia
456212
456212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029867%2fkeras-functional-api-multi-input-layer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The funcional API guide describes exactly how to make multiple input models keras.io/getting-started/functional-api-guide your problem is that you have to give the inputs (x1, x2, x3), not the layer after that.
– Matias Valdenegro
Jan 3 at 21:16