Branch fusion
Combine parallel neural-network branches by multiplying their corresponding activations.
Keras · Class
Keras Multiply performs elementwise multiplication on a list of same-shaped tensors and returns one tensor with that shape. It is useful for combining parallel branches or applying tensor-valued gates.
Multiply receives a list of tensors and combines them by multiplying corresponding elements. The result keeps the same shape as the inputs, so each input must have matching dimensions.
keras.layers.Multiply(**kwargs)A single tensor with the same shape as the input tensors.
import numpy as np
import keras
x1 = np.array([[1., 2., 3.]])
x2 = np.array([[4., 5., 6.]])
y = keras.layers.Multiply()([x1, x2])
print(y) # [[ 4. 10. 18.]]Creates a Multiply layer and applies it to two same-shaped arrays.
Combine parallel neural-network branches by multiplying their corresponding activations.
Apply a learned or computed tensor as an elementwise gate to another tensor.
Build Functional API graphs where multiple symbolic outputs must be combined multiplicatively.
Multiply performs elementwise multiplication over a list of tensors and returns one tensor. The inputs must all have the same shape, and the output preserves that shape.
Follow-up: How could you use it in a Functional model? Pass multiple symbolic tensors as a list to keras.layers.Multiply(), then connect the returned tensor to subsequent layers.
Its call input is a list rather than a single tensor. Each position in the list is multiplied element by element with the corresponding positions from the other tensors.
Follow-up: What shape constraint follows from this behavior? Every tensor supplied to the layer must have the same shape.
Instantiate it with keras.layers.Multiply(**kwargs) and invoke it with tensors, for example keras.layers.Multiply()([x1, x2]). The output is a single tensor with the inputs' shape.
Follow-up: What is the functional equivalent named in the documentation? The equivalent operation is keras.layers.multiply([x1, x2]).
keras.layers.multiplykeras.layers.Addkeras.layers.Averagekeras.layers.Maximumkeras.layers.Minimum