Skip to content
Advertisement

Concatenate two models with tensorflow.keras

I’m currently studying neural network models for image analysis, with the MNIST dataset. I first used only the image to build a first model. Then I created a additionnal variable, which is : 0 when the digit is actually between 0 and 4, and 1 when it’s greater or equal than 5.

Therefore, I want to build a model that can take these two informations : the image of the digit, and that additionnal variable I juste created.

I created the two first models, one for the image and one for the exogenous variable, as follow :

JavaScript

Then I would like to concatenate both final layers, to finally put another dense layer with softmax to predict class probabilities.

I know it’s feasible using Keras functionnal API, but how could one do it using tf.keras ?

Advertisement

Answer

You can easily use Keras’ functional API in TF (tested with TF 2.0):

JavaScript

Which gives you the model you are looking for.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement