Merge layers
1. Merge layers
Now that you've got multiple inputs and a shared layer, you need to combine your inputs into a single layer that you can use to predict a single output. This requires a Merge layer. Merge layers allow you to define advanced, non-sequential network topologies. This can give you a lot of flexibility to creatively design networks to solve specific problems.2. Merge layers
There are many kinds of merge layers available in Keras. Add, Subtract, and Multiply layers do simple arithmetic operations by element on the input layers, and require them to be the same shape. For example, if we wanted to multiply our team strength ratings together, we could use a Multiply layer. Concatenate layers simply append the 2 layers together, similar to the hstack() function from numpy. Unlike the other merge layers, the Concatenate layer can operate on layers with different numbers of columns.3. Merge layers
Let's build a simple Keras model that takes in two numbers and adds them together. You accomplish this by defining two input layers and using the Add layer to add them together.4. Merge layers
If you'd like to add together many inputs, you can pass a list with more than two elements to an Add layer. Note that all of the inputs are required to have the same shape, so they can be combined element-wise. The Subtract and Multiply layers work the same way.5. Create the model
Now you can wrap the output from your Add layer inside a Model, which will then allow you to fit it to data. Note that the model takes in a list of inputs because it has more than one input.6. Compile the model
As with other Keras models, you need to compile it before fitting. Use the "adam" optimizer and mean absolute error as the loss function.7. Let's practice!
Now you can practice using merge layers.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.