Computes the Generalized Mean of each channel in a tensor.
Inherits From: GeneralizedMeanPooling
TFSimilarity.layers.GeneralizedMeanPooling1D(
p: float = 3.0,
data_format: Optional[str] = None,
keepdims: bool = False,
**kwargs
) -> None
$$ \textbfe} = \left[\left(\frac{1}{|\Omega|}\sum_{u\in{\Omega}}x^{p}{cu}\right)^{\frac{1}{p}}\right]{c=1,\cdots,C $$
The Generalized Mean (GeM) provides a parameter p that sets an exponent enabling the pooling to increase or decrease the contrast between salient features in the feature map.
The pooling is equal to GlobalAveragePooling1D when p is 1.0 and equal to MaxPool1D when p is inf.
This implementation shifts the feature map values such that the minimum value is equal to 1.0, then computes the mean pooling, and finally shifts the values back. This ensures that all values are positive as the generalized mean is only valid over positive real values.
p | Set the power of the mean. A value of 1.0 is equivalent to the arithmetic mean, while a value of inf is equivalent to MaxPool2D. Note, math.inf, -math.inf, and 0.0 are all supported, as well as most positive and negative values of p. However, large positive values for p may lead to overflow. In practice, math.inf should be used for any p larger than > 25. |
data_format | One of channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch, steps, features) while channels_first corresponds to inputs with shape (batch, features, steps). |
keepdims | A boolean, whether to keep the temporal dimension or not. If keepdims is False (default), the rank of the tensor is reduced for spatial dimensions. If keepdims is True, the temporal dimension are retained with length 1. The behavior is the same as for tf.reduce_max or np.max. |
- If data_format='channels_last': 3D tensor with shape: (batch_size, steps, features)
- If data_format='channels_first': 3D tensor with shape: (batch_size, features, steps)
- If keepdims=False: 2D tensor with shape (batch_size, features).
- If keepdims=True:
- If data_format='channels_last': 3D tensor with shape (batch_size, 1, features)
- If data_format='channels_first': 3D tensor with shape (batch_size, features, 1)