簡體   English   中英

Keras功能API多輸入層

[英]Keras Functional API Multi Input Layer

如何使用Keras Functional API定義多輸入層? 以下是我要構建的神經網絡的示例。 有三個輸入節點。 我希望每個節點都是不同長度的一維numpy數組。

到目前為止,這就是我所擁有的。 基本上,我想定義一個具有多個輸入張量的輸入層。

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()

神經網絡

該代碼給出了錯誤。

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)

更改

model = Model(inputs=input_layer,outputs=prediction)

model = Model(inputs=[x1, x2, x3],outputs=prediction)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM