GlobalAveragePooling1D
类keras.layers.GlobalAveragePooling1D(data_format=None, keepdims=False, **kwargs)
用于时间数据的全局平均池化操作。
参数
"channels_last"
或 "channels_first"
。输入中维度的顺序。"channels_last"
对应于形状为 (batch, steps, features)
的输入,而 "channels_first"
对应于形状为 (batch, features, steps)
的输入。它默认为在您的 Keras 配置文件 ~/.keras/keras.json
中找到的 image_data_format
值。如果您从未设置过,则它将为 "channels_last"
。keepdims
为 False
(默认),则张量的秩对于空间维度会降低。如果 keepdims
为 True
,则时间维度将被保留,长度为 1。此行为与 tf.reduce_mean
或 np.mean
相同。调用参数
(batch_size, steps)
的二进制张量,指示是否应屏蔽(从平均值中排除)给定的步骤。输入形状
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=True
:- 如果 data_format="channels_last"
:3D 张量,形状为 (batch_size, 1, features)
- 如果 data_format="channels_first"
:3D 张量,形状为 (batch_size, features, 1)
示例
>>> x = np.random.rand(2, 3, 4)
>>> y = keras.layers.GlobalAveragePooling1D()(x)
>>> y.shape
(2, 4)