[英]Keras Functional API Multi Input Layer
How do I define a multi input layer using Keras Functional API? 如何使用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.
我希望每个节点都是不同长度的一维numpy数组。
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. 稍后,当我拟合模型时,我将传入一列具有相应长度的numpy数组。
输入必须是您的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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.