Hag*_*ard 4 python keras tensorflow
当谈到 Keras 的平均池化层时,我有点困惑。文档说明如下:
AveragePooling1D:时态数据的平均池化。
参数
Run Code Online (Sandbox Code Playgroud)pool_size: Integer, size of the average pooling windows. strides: Integer, or None. Factor by which to downscale. E.g. 2 will halve the input. If None, it will default to pool_size. padding: One of "valid" or "same" (case-insensitive). data_format: A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs.channel_last 对应于具有形状(批次、步骤、特征)的输入,而 channels_first 对应于具有形状(批次、特征、步骤)的输入。
输入形状
Run Code Online (Sandbox Code Playgroud)If data_format='channels_last': 3D tensor with shape: (batch_size, steps, features) If data_format='channels_first': 3D tensor with shape: (batch_size, features, steps)输出形状
Run Code Online (Sandbox Code Playgroud)If data_format='channels_last': 3D tensor with shape: (batch_size, downsampled_steps, features) If data_format='channels_first': 3D tensor with shape: (batch_size, features, downsampled_steps)
和
GlobalAveragePooling1D:时态数据的全局平均池化操作。
参数
Run Code Online (Sandbox Code Playgroud)data_format: A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs.channel_last 对应于具有形状(批次、步骤、特征)的输入,而 channels_first 对应于具有形状(批次、特征、步骤)的输入。
输入形状
Run Code Online (Sandbox Code Playgroud)If data_format='channels_last': 3D tensor with shape: (batch_size, steps, features) If data_format='channels_first': 3D tensor with shape: (batch_size, features, steps)输出形状
具有形状的 2D 张量:(batch_size, features)
我(认为我)确实得到了平均池化的概念,但我真的不明白为什么 GlobalAveragePooling1D 层只是简单地删除了步骤参数。非常感谢您的回答。
GlobalAveragePooling1D是一样AveragePooling1D用pool_size=steps。因此,对于每个特征维度,它在所有时间步长中取平均值。因此输出具有形状(batch_size, 1, features)(如果data_format='channels_last')。他们只是将第二个(或第三个 if data_format='channels_first')维度展平,这就是您获得等于 的输出形状的方式 (batch_size, features)。