Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

layers.Add

keras.layers.Add merges a list of same-shaped tensors by adding them elementwise. It returns one tensor with that same shape.

How it works

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.

Syntax

keras.layers.Add(**kwargs)

Returns

A single tensor with the same shape as the input tensors.

Key points

  • It adds corresponding elements across the supplied tensors.
  • The layer produces one tensor and retains the shared input shape.
  • Use it as a node in a Functional model to merge parallel branches.
  • Construct it with the Keras layers.Add class and optional base-layer keyword arguments.
  • The callable Add layer has a functional shorthand, keras.layers.add, for the same merge.

Common mistakes

  • Pass a list rather than a single tensor, and ensure every tensor in that list has the same shape.

Example: Adding two 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.

When to use it

Combine a block output with its shortcut branch.

Residual connections

Merge compatible representations from multiple paths.

Parallel feature branches

Join multiple input tensors at a graph node.

Functional models

Interview questions

QWhat does keras.layers.Add do?

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.

QWhat shape constraints apply to 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.

QHow is Add used in the Keras Functional API?

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.add
  • keras.layers.Concatenate
  • keras.layers.Average
  • keras.layers.Maximum

Source: Add layer. Checked 2026-10-15.