python - 具有不同输入的集成模型

标签 python keras ensemble-learning

我实例化了 3 个简单的不太深的模型(可以根据我的喜好更深)并用 3 个单独的输入来训练它们。需要明确的是,第一个输入是人脸图像,第二个输入是眼睛,第三个输入是嘴巴(用于面部表情识别)。我想集成一个模型,我提供 3 个输入(具有所有相同的类标签 ofc)并获得单个标签输出。其动机是 90% 准确的模型在集成在一起时可能会表现得更好。它应该看起来像这样:

Facial input-----------Eyes Input------------Mouth Input
 (100x100x1)          (100x100x1)          (100x100x1) 
     |                     |                     | 

   .....                 ......                .....

     |                     |                     |
      ___________________________________________
                 Some concatenation over here
                           |
                   | Output Label|    

或者我应该完全忘记这一点;测试后获取每个模型底层Dense层的响应,并将它们组合成特征向量并进行分类。在这里一无所知...

最佳答案

假设您的模型名为 model1model2model3。 您可以使用 functional API像这样合并你的模型:

input1 = model1.input
input2 = model2.input
input3 = model3.input

m1 = model1(input1)
m2 = model2(input2)
m3 = model3(input3)

output = concatenate([m1, m2, m3]) # this is the concatenation
output = Dense(10)(output) # just an example for what you could add to the model
output = Activation('softmax')(output)

model = Model(inputs=[input1,input2,input3], outputs=output)
然后可以训练

model,它将同时训练所有三个模型。如果您只想训练三个模型之上的模型部分,可以使用trainable参数。

关于python - 具有不同输入的集成模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54884095/

相关文章:

python - 在 Keras 问题中实现暹罗网络

python - 属性错误: module "sklearn.utils" has no attribute "_joblib" when inheriting class `sklearn.ensemble.BaggingClassifier.`

machine-learning - 使用 scikit-learn(或任何其他 python 框架)的不同类型回归器的集合

python - 使用 crontab 执行脚本时登录 python

python - scrapy - 如果跟随无限网站则终止抓取

python - 如何在 Python 中检测 Meego/Maemo 平台?

python - 如何在 Keras Lambda 层中使用 OpenCV 函数?

python - 使用 tf.keras.layers.Reshape 时出现类型错误

machine-learning - 什么是弱学习者?

python 提取日期