GlobalMaxPooling1D 类tf_keras.layers.GlobalMaxPooling1D(
data_format="channels_last", keepdims=False, **kwargs
)
1D 时间数据的全局最大池化操作。
通过在时间维度上取最大值来下采样输入表示。
例如
>>> x = tf.constant([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])
>>> x = tf.reshape(x, [3, 3, 1])
>>> x
<tf.Tensor: shape=(3, 3, 1), dtype=float32, numpy=
array([[[1.], [2.], [3.]],
[[4.], [5.], [6.]],
[[7.], [8.], [9.]]], dtype=float32)>
>>> max_pool_1d = tf.keras.layers.GlobalMaxPooling1D()
>>> max_pool_1d(x)
<tf.Tensor: shape=(3, 1), dtype=float32, numpy=
array([[3.],
[6.],
[9.], dtype=float32)>
参数
channels_last(默认)或 channels_first。输入中维度的顺序。channels_last 对应于形状为 (batch, steps, features) 的输入,而 channels_first 对应于形状为 (batch, features, steps) 的输入。keepdims 为 False(默认),则空间维度的张量秩会降低。如果 keepdims 为 True,则时间维度将被保留,长度为 1。其行为与 tf.reduce_max 或 np.max 相同。输入形状
data_format='channels_last':形状为 (batch_size, steps, features) 的 3D 张量data_format='channels_first':形状为 (batch_size, features, steps) 的 3D 张量输出形状
keepdims=False:形状为 (batch_size, features) 的 2D 张量。keepdims=Truedata_format='channels_last':形状为 (batch_size, 1, features) 的 3D 张量data_format='channels_first':形状为 (batch_size, features, 1) 的 3D 张量