我实例化了 3 个简单的不太深的模型(可以根据我的喜好更深)并用 3 个单独的输入来训练它们。需要明确的是,第一个输入是人脸图像,第二个输入是眼睛,第三个输入是嘴巴(用于面部表情识别)。我想集成一个模型,我提供 3 个输入(具有所有相同的类标签 ofc)并获得单个标签输出。其动机是 90% 准确的模型在集成在一起时可能会表现得更好。它应该看起来像这样:
Facial input-----------Eyes Input------------Mouth Input
(100x100x1) (100x100x1) (100x100x1)
| | |
..... ...... .....
| | |
___________________________________________
Some concatenation over here
|
| Output Label|
或者我应该完全忘记这一点;测试后获取每个模型底层Dense
层的响应,并将它们组合成特征向量并进行分类。在这里一无所知...
最佳答案
假设您的模型名为 model1
、model2
和 model3
。
您可以使用 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/