具有不同输入的集成模型
Ensembling models with different inputs
我实例化了 3 个简单的不太深的模型(可以更深,因为我喜欢)并用 3 个单独的输入训练它们。明确地说,第一个输入是人脸图像,第二个是眼睛,第三个是嘴巴(用于面部表情识别)。我想集成一个模型,我用 3 个输入(具有相同的 class 标签 ofc)提供并获得单个标签输出。动机是 90% 准确的模型在集成在一起时可能表现更好。它应该是这样的:
Facial input-----------Eyes Input------------Mouth Input
(100x100x1) (100x100x1) (100x100x1)
| | |
..... ...... .....
| | |
___________________________________________
Some concatenation over here
|
| Output Label|
或者我应该完全忘记这个;获取每个模型测试后底层Dense
层的响应,并将它们组合成一个特征向量并classify。在这里一无所知...
假设您的模型名为 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
参数。
我实例化了 3 个简单的不太深的模型(可以更深,因为我喜欢)并用 3 个单独的输入训练它们。明确地说,第一个输入是人脸图像,第二个是眼睛,第三个是嘴巴(用于面部表情识别)。我想集成一个模型,我用 3 个输入(具有相同的 class 标签 ofc)提供并获得单个标签输出。动机是 90% 准确的模型在集成在一起时可能表现更好。它应该是这样的:
Facial input-----------Eyes Input------------Mouth Input
(100x100x1) (100x100x1) (100x100x1)
| | |
..... ...... .....
| | |
___________________________________________
Some concatenation over here
|
| Output Label|
或者我应该完全忘记这个;获取每个模型测试后底层Dense
层的响应,并将它们组合成一个特征向量并classify。在这里一无所知...
假设您的模型名为 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
参数。