简体   繁体   中英

Keras Functional API Multi Input Layer

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.

输入必须是您的Input()层:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM