一维时间数据的全局最大池化操作。
用法
tf.keras.layers.GlobalMaxPool1D(
data_format='channels_last', keepdims=False, **kwargs
)
参数
-
data_format
一个字符串,是channels_last
(默认)或channels_first
之一。输入中维度的排序。channels_last
对应于形状为(batch, steps, features)
的输入,而channels_first
对应于形状为(batch, features, steps)
的输入。 -
keepdims
一个布尔值,是否保持时间维度。如果keepdims
是False
(默认),则张量的秩会针对空间维度降低。如果keepdims
是True
,则保留长度为 1 的时间维度。行为与tf.reduce_max
或np.max
相同。
通过在时间维度上取最大值来对输入表示进行下采样。
例如:
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)>
输入形状:
- 如果
data_format='channels_last'
:具有形状的 3D 张量:(batch_size, steps, features)
- 如果
data_format='channels_first'
:具有形状的 3D 张量:(batch_size, features, steps)
输出形状:
- 如果
keepdims
=False:形状为(batch_size, features)
的二维张量。 - 如果
keepdims
=真:- 如果
data_format='channels_last'
:形状为(batch_size, 1, features)
的 3D 张量 - 如果
data_format='channels_first'
:形状为(batch_size, features, 1)
的 3D 张量
- 如果
相关用法
- Python tf.keras.layers.GlobalMaxPool2D用法及代码示例
- Python tf.keras.layers.GlobalAveragePooling1D用法及代码示例
- Python tf.keras.layers.GlobalAveragePooling2D用法及代码示例
- Python tf.keras.layers.GRUCell用法及代码示例
- Python tf.keras.layers.GRU用法及代码示例
- Python tf.keras.layers.InputLayer用法及代码示例
- Python tf.keras.layers.serialize用法及代码示例
- Python tf.keras.layers.Dropout用法及代码示例
- Python tf.keras.layers.maximum用法及代码示例
- Python tf.keras.layers.LayerNormalization用法及代码示例
- Python tf.keras.layers.Conv2D用法及代码示例
- Python tf.keras.layers.RepeatVector用法及代码示例
- Python tf.keras.layers.Multiply用法及代码示例
- Python tf.keras.layers.Activation用法及代码示例
- Python tf.keras.layers.Conv1D用法及代码示例
- Python tf.keras.layers.experimental.preprocessing.PreprocessingLayer.adapt用法及代码示例
- Python tf.keras.layers.CategoryEncoding用法及代码示例
- Python tf.keras.layers.subtract用法及代码示例
- Python tf.keras.layers.experimental.preprocessing.HashedCrossing用法及代码示例
- Python tf.keras.layers.Subtract用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.keras.layers.GlobalMaxPool1D。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。