9

I created two convolutional neural networks (CNN), and I want to make these networks work in parallel. Each network takes different type of images and they join in the last fully connected layer.

How to do this?

Ethan
  • 1,633
  • 9
  • 24
  • 39
N.IT
  • 1,995
  • 4
  • 19
  • 35

1 Answers1

8

You essentially need a multi-input model. This can only be done through keras' functional api and can work with the pretrained nets in keras.applications. To create one you can do this:

from keras.layers import Input, Conv2D, Dense, concatenate
from keras.models import Model

1) Define your first model:

 in1 = Input(...)  # input of the first model
 x = Conv2D(...)(in1)
 # rest of the model
 out1 = Dense(...)(x)  # output for the first model

2) Define your second model:

 in2 = Input(...)  # input of the first model
 x = Conv2D(...)(in2)
 # rest of the model
 out2 = Dense(...)(x)  # output for the first model

3) Merge the two models and conclude the network:

x = concatenate([out1, out2])  # merge the outputs of the two models
out = Dense(...)(x)  # final layer of the network

4) Create the Model:

model = Model(inputs=[in1, in2], outputs=[out])
Djib2011
  • 7,968
  • 5
  • 27
  • 37
  • https://stackoverflow.com/questions/68330534/merge-multiple-models-in-keras-tensorflow?noredirect=1#comment120763705_68330534 Can you help with this problem? – Coder Jul 10 '21 at 20:01
  • @Coder I'm not sure what you're referring to... You could ask a new question if you like and I (along with a lot of other contributors in this site) will be happy to answer! – Djib2011 Jul 12 '21 at 06:55
  • Hii, That question is posted by me. can you please answer it! – Coder Jul 12 '21 at 07:36