如何使用Keras函数式API定义一个多输入层?下面是我想要构建的神经网络的一个例子。有三个输入节点。我希望每个节点是一个不同长度的一维numpy数组。
这是我目前的代码。基本上我想定义一个具有多个输入张量的输入层。
from keras.layers import Input, Dense, Dropout, concatenatefrom keras.models import Modelx1 = 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()
代码出现了以下错误:
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: []
稍后当我拟合模型时,我将传入一个对应长度的一维numpy数组列表。
回答:
输入必须是你的 Input()
层:
model = Model(inputs=[x1, x2, x3],outputs=prediction)