I want to make a network, specifically a CNN for image recognition, that takes an input, processes it the same way for several layers, and then at some point splits before coming to two different outputs. Is it possible to create a network such as this? It would look something like this:

Input -> Conv -> Pool -> Conv -> Pool ---------> Dense -> Output 1


                                     ----> Dense -> Output 2

I.E. it splits off after the second pooling layer into separate fully connected layers. Of course, it has to train to both outputs, so that it is producing minimal error on both separate outputs using these common convolutional layers. Also, I am using Python Keras, and it would help if there was some way to do this using Keras in some way. Thank you!


1 Answer 1


Keras Functional APIs can help you define complex models.

You can find the documentation here : https://keras.io/getting-started/functional-api-guide/.

For example:

# prev_layer is the layer you want to be forked
fork1 = Dense(32, activation='relu')(prev_layer)
fork2 = Dense(32, activation='relu')(prev_layer)

# you do some operations on fork1 to get output1
# and on fork2 to get output2

model = Model(inputs=input_layer, outputs=[output1, output2])

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .