GlobalMaxPooling1D
类tf_keras.layers.GlobalMaxPooling1D(
data_format="channels_last", keepdims=False, **kwargs
)
用于一维时序数据的全局最大池化操作。
通过在时间维度上取最大值来对输入表示进行降采样。
例如
>>> 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'
: 3D 张量,形状为:(batch_size, steps, features)
data_format='channels_first'
: 3D 张量,形状为:(batch_size, features, steps)
输出形状
keepdims
=False: 2D 张量,形状为 (batch_size, features)
。keepdims
=Truedata_format='channels_last'
: 3D 张量,形状为 (batch_size, 1, features)
data_format='channels_first'
: 3D 张量,形状为 (batch_size, features, 1)