如何在Keras中将以下顺序模型转换为功能模型 [英] How to convert the following sequential model into a functional model in keras

查看:65
本文介绍了如何在Keras中将以下顺序模型转换为功能模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the following sequential model in 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编写相同的模型.我尝试这样做,如下.

Now, I want to write the same model in functional Keras. I tried to do it as follows.

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

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

However, the results I get are completely different. So, I am thinking the way I converted my original sequential model is incorrect.

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

I am happy to provide more details if needed.

推荐答案

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'])

这篇关于如何在Keras中将以下顺序模型转换为功能模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆