python - 如何将以下顺序模型转换为keras中的函数模型

标签 python machine-learning keras deep-learning lstm

我在 Keras 中使用以下顺序模型。

model = Sequential()
model.add(LSTM(150, input_shape=(29,3)))
model.add(Dense(100))
model.add(Dropout(0.2))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

现在,我想在函数式 Keras 中编写相同的模型。我尝试按如下方式进行操作。

input1 = Input(shape=(29,1))
x1 = LSTM(50)(input1)
input2 = Input(shape=(29,1))
x2 = LSTM(50)(input2)
input3 = Input(shape=(29,1))
x3 = LSTM(50)(input3)    
x = concatenate([x1,x2,x3])

但是,我得到的结果却完全不同。所以,我认为我转换原始顺序模型的方式是不正确的。

如果需要,我很乐意提供更多详细信息。

最佳答案

inputs = Input(shape=(29,3))
outputs = LSTM(150)(inputs)
outputs = Dense(100)(outputs)
outputs = Dropout(0.2)(outputs)
outputs = Dense(1, activation='sigmoid')(outputs)

model = Model(inputs, outputs)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

关于python - 如何将以下顺序模型转换为keras中的函数模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59081232/

相关文章:

keras - 使用来自 Keras 应用程序的模型,无需预训练权重

tensorflow - 不平衡数据集上的一类文本分类

python - 如何将 ModelAdmins 从一个应用程序拆分到多个 block

python - 跨平台路径交换

python - 将 NULL 值插入 double 据类型 MySQL Python

machine-learning - 为什么我们要在分类问题中最大化 AUC?

python - 将 Keras 模型转换为多标签输出

python - 比较 panda 数据框中的值并返回新值

python - python中的任何朴素贝叶斯分类器?

javascript - 谁能告诉我如何在按下鼠标并继续直到它在 p5.js 中被释放时触发一个函数