我创建了两个卷积神经网络 (CNN),我想让这些网络并行工作。每个网络采用不同类型的图像,它们加入最后一个全连接层。
这个怎么做?
我创建了两个卷积神经网络 (CNN),我想让这些网络并行工作。每个网络采用不同类型的图像,它们加入最后一个全连接层。
这个怎么做?
您本质上需要一个多输入模型。这只能通过 keras 的功能 api 完成,并且可以与keras.applications
. 要创建一个,您可以这样做:
from keras.layers import Input, Conv2D, Dense, concatenate
from keras.models import Model
1)定义你的第一个模型:
in1 = Input(...) # input of the first model
x = Conv2D(...)(in1)
# rest of the model
out1 = Dense(...)(x) # output for the first model
2)定义你的第二个模型:
in2 = Input(...) # input of the first model
x = Conv2D(...)(in2)
# rest of the model
out2 = Dense(...)(x) # output for the first model
3)合并两个模型并总结网络:
x = concatenate([out1, out2]) # merge the outputs of the two models
out = Dense(...)(x) # final layer of the network
4)创建模型:
model = Model(inputs=[in1, in2], outputs=[out])