Feature fusion
Combining parallel branches in a neural network
Keras · Class
Keras Concatenate joins a list of tensors along one chosen axis. Inputs must have matching shapes on every other axis, and the default join axis is the last one.
Concatenate accepts a list of tensors and joins them along the selected axis. Every dimension other than that axis must match, and the resulting tensor has the combined size along the chosen axis.
keras.layers.Concatenate(axis=-1, **kwargs)| Name | Type | Description |
|---|---|---|
axis | int | Axis along which to concatenate. |
**kwargs | dict | Standard layer keyword arguments. |
A tensor, the concatenation of the inputs alongside axis axis.
import numpy as np
import keras
x = np.arange(20).reshape(2, 2, 5)
y = np.arange(20, 30).reshape(2, 1, 5)
result = keras.layers.Concatenate(axis=1)([x, y])
print(result.shape) # (2, 3, 5)Concatenates two tensors along their second axis while preserving the other dimensions.
Combining parallel branches in a neural network
Merging embeddings or encoded representations
Joining spatial or sequence tensors along a compatible dimension
It joins a list of tensors into one tensor along the configured axis. The inputs must have identical shapes everywhere except on that axis.
Follow-up: What happens to the selected dimension? Its size becomes the sum of that dimension across all input tensors.
The default axis is -1, so concatenation occurs on the last dimension unless another axis is supplied. For example, axis=1 joins the tensors along their second dimension.
Follow-up: Why might axis=-1 be convenient? It commonly combines feature dimensions while leaving batch and earlier structural dimensions unchanged.
The layer is called with a list of tensors, such as keras.layers.Concatenate()([x1, x2]). It returns a single tensor representing their concatenation.
Follow-up: How can it be used in a model? Apply it to outputs from parallel layers before passing the merged tensor to a subsequent layer.
keras.layers.Addkeras.layers.Averagekeras.layers.Multiplykeras.layers.Cropping1Dkeras.layers.Cropping2D