Keras 3 API 文档 / 层 API / 池化层 / GlobalAveragePooling3D 层

GlobalAveragePooling3D 层

[源代码]

GlobalAveragePooling3D

keras.layers.GlobalAveragePooling3D(data_format=None, keepdims=False, **kwargs)

3D 数据的全局平均池化操作。

参数

  • data_format: 字符串,可以是 "channels_last""channels_first"。输入维度顺序。"channels_last" 对应形状为 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的输入,而 "channels_first" 对应形状为 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的输入。默认为 Keras 配置文件 ~/.keras/keras.json 中找到的 image_data_format 值。如果从未设置过,则默认为 "channels_last"
  • keepdims: 布尔值,是否保留时间维度。如果 keepdimsFalse(默认值),则张量的秩将针对空间维度降低。如果 keepdimsTrue,则保留空间维度,长度为 1。行为与 tf.reduce_meannp.mean 相同。

输入形状

  • 如果 data_format='channels_last': 5D 张量,形状为:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
  • 如果 data_format='channels_first': 5D 张量,形状为:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)

输出形状

  • 如果 keepdims=False: 2D 张量,形状为 (batch_size, channels)
  • 如果 keepdims=True: - 如果 data_format="channels_last": 5D 张量,形状为 (batch_size, 1, 1, 1, channels) - 如果 data_format="channels_first": 5D 张量,形状为 (batch_size, channels, 1, 1, 1)

示例

>>> x = np.random.rand(2, 4, 5, 4, 3)
>>> y = keras.layers.GlobalAveragePooling3D()(x)
>>> y.shape
(2, 3)