一維時間數據的全局最大池化操作。
用法
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。