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?


1 Answer 1


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])
  • $\begingroup$ stackoverflow.com/questions/68330534/… Can you help with this problem? $\endgroup$
    – Coder
    Jul 10, 2021 at 20:01
  • $\begingroup$ @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! $\endgroup$
    – Djib2011
    Jul 12, 2021 at 6:55
  • $\begingroup$ Hii, That question is posted by me. can you please answer it! $\endgroup$
    – Coder
    Jul 12, 2021 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.