Keras Functional API 多输入层

如何使用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()

Neural Network

代码出现了以下错误:

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)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注