GlobalAveragePooling2D
类keras.layers.GlobalAveragePooling2D(data_format=None, keepdims=False, **kwargs)
用于二维数据的全局平均池化操作。
参数
"channels_last"
或 "channels_first"
。输入数据的维度顺序。"channels_last"
对应于形状为 (batch, height, width, channels)
的输入,而 "channels_first"
对应于形状为 (batch, features, height, weight)
的输入。默认为 Keras 配置文件 ~/.keras/keras.json
中的 image_data_format
值。如果从未设置过,则默认为 "channels_last"
。keepdims
为 False
(默认值),则张量的秩会针对空间维度降低。如果 keepdims
为 True
,则空间维度将保留,长度为 1。行为与 tf.reduce_mean
或 np.mean
相同。输入形状
data_format='channels_last'
:4D 张量,形状为:(batch_size, height, width, channels)
data_format='channels_first'
:4D 张量,形状为:(batch_size, channels, height, width)
输出形状
keepdims=False
:2D 张量,形状为 (batch_size, channels)
。keepdims=True
: - 如果 data_format="channels_last"
:4D 张量,形状为 (batch_size, 1, 1, channels)
- 如果 data_format="channels_first"
:4D 张量,形状为 (batch_size, channels, 1, 1)
示例
>>> x = np.random.rand(2, 4, 5, 3)
>>> y = keras.layers.GlobalAveragePooling2D()(x)
>>> y.shape
(2, 3)