Combine a block output with its shortcut branch.
Residual connections
Keras · Class
keras.layers.Add merges a list of same-shaped tensors by adding them elementwise. It returns one tensor with that same shape.
Add accepts a list of tensors and combines corresponding elements into one tensor. The inputs must share a shape, and the result preserves that shape, making the layer useful for residual and multi-branch connections.
keras.layers.Add(**kwargs)A single tensor with the same shape as the input tensors.
import keras
from keras import layers
x1 = keras.Input(shape=(8,))
x2 = keras.Input(shape=(8,))
y = layers.Add()([x1, x2])
model = keras.Model([x1, x2], y)
result = model([
keras.ops.ones((2, 8)),
keras.ops.ones((2, 8)),
])
print(result.shape)Creates a functional model that adds two compatible batches element by element.
Residual connections
Parallel feature branches
Functional models
Add performs elementwise addition on a list of tensors. It returns one tensor whose shape matches the input tensors.
Follow-up: How would you connect branches with different source feature sizes? First transform each branch, for example with Dense layers, so their outputs have matching shapes before applying Add.
Each input must have the same shape because the operation adds corresponding elements directly. The output is also the same shape as each input.
Follow-up: Why might Add be preferable to concatenation in a residual block? It preserves the feature width instead of increasing it, while directly combining the branches.
Instantiate the layer and call it with a list, such as layers.Add()([x1, x2]). In a functional model, the resulting tensor can then feed subsequent layers.
Follow-up: What is the functional-model equivalent shorthand? The documentation identifies keras.layers.add([x1, x2]) as equivalent to the Add layer form.
keras.layers.addkeras.layers.Concatenatekeras.layers.Averagekeras.layers.Maximum