Search code examples
keraskeras-layerkeras-2

How do you use Add in Keras


In keras say you have

layer1

and

layer2

You want to add these two layers, and you have to use Add from keras.layers.merge and you can't use the functional api.

Add doesn't take any inputs, so I don't see how it can possibly help in setting up the graph. I'm using keras 2.06.


Solution

  • If you take the sum of two layers like that, your network graph would look like this

       |        |
    layer1    layer2
        \      /
         \    /
          \  /
           \/
          sum
    

    Such a layer is by definition not sequential (since sum takes more than one input), so performing this using the Sequential API is impossible. You must use the Functional API.