Combine predictions or representations from parallel branches by averaging corresponding values.
Ensemble-style merging
Keras · Class
keras.layers.Average computes the element-wise mean of a list of same-shaped tensors. It returns one tensor with the same shape, making it useful for merging parallel Keras branches.
Average receives multiple tensors with matching shapes and computes their element-wise mean, returning one tensor with that same shape. It can be called directly with tensor values or inserted into a functional Keras model to merge parallel branches.
keras.layers.Average(**kwargs)A single tensor with the same shape as the inputs, containing their element-wise average.
**kwargs.import numpy as np
import keras
x1 = np.array([[1., 2., 3.]])
x2 = np.array([[3., 4., 5.]])
y = keras.layers.Average()([x1, x2])
print(y)
Averages two same-shaped tensors element by element, producing [[2., 3., 4.]].
Ensemble-style merging
Functional models
Multi-branch architectures
Average merges a list of tensors by calculating their element-wise mean. The result keeps the same shape as each input.
Follow-up: What must be true before merging? Every tensor in the input list must have matching shape.
Instantiate keras.layers.Average() and call it with a list, such as layer([x1, x2]). The list contains the tensors to combine.
Follow-up: How would you use it in a model? Connect parallel branches to the layer and pass its output to later layers.
The layer is useful for combining parallel model branches when their outputs have identical shapes. It produces one tensor rather than concatenating or increasing the feature dimension.
Follow-up: How does this differ from concatenation? Concatenation joins values along an axis and generally changes that dimension, whereas averaging preserves the branch shape.
keras.layers.Addkeras.layers.Maximumkeras.layers.Minimumkeras.layers.average