AveragePooling1D
类keras.layers.AveragePooling1D(
pool_size, strides=None, padding="valid", data_format=None, name=None, **kwargs
)
用于时间序列数据的平均池化。
通过对由pool_size
定义的窗口内取平均值的方式对输入表示进行降采样。窗口以strides
为步长进行移动。当使用“valid”填充选项时,结果输出的形状为:output_shape = (input_shape - pool_size + 1) / strides)
当使用“same”填充选项时,结果输出形状为:output_shape = input_shape / strides
参数
pool_size
。"valid"
或"same"
(不区分大小写)。"valid"
表示不填充。"same"
导致在输入的左侧/右侧或上下进行均匀填充,使得输出具有与输入相同的高度/宽度维度。"channels_last"
或"channels_first"
。输入中维度的顺序。"channels_last"
对应于形状为(batch, steps, features)
的输入,而"channels_first"
对应于形状为(batch, features, steps)
的输入。它默认为在您的 Keras 配置文件 ~/.keras/keras.json
中找到的image_data_format
值。如果您从未设置它,则它将为"channels_last"
。输入形状
data_format="channels_last"
:3D 张量,形状为(batch_size, steps, features)
。data_format="channels_first"
:3D 张量,形状为(batch_size, features, steps)
。输出形状
data_format="channels_last"
:3D 张量,形状为(batch_size, downsampled_steps, features)
。data_format="channels_first"
:3D 张量,形状为(batch_size, features, downsampled_steps)
。示例
strides=1
和 padding="valid"
>>> x = np.array([1., 2., 3., 4., 5.])
>>> x = np.reshape(x, [1, 5, 1])
>>> avg_pool_1d = keras.layers.AveragePooling1D(pool_size=2,
... strides=1, padding="valid")
>>> avg_pool_1d(x)
strides=2
和 padding="valid"
>>> x = np.array([1., 2., 3., 4., 5.])
>>> x = np.reshape(x, [1, 5, 1])
>>> avg_pool_1d = keras.layers.AveragePooling1D(pool_size=2,
... strides=2, padding="valid")
>>> avg_pool_1d(x)
strides=1
和 padding="same"
>>> x = np.array([1., 2., 3., 4., 5.])
>>> x = np.reshape(x, [1, 5, 1])
>>> avg_pool_1d = keras.layers.AveragePooling1D(pool_size=2,
... strides=1, padding="same")
>>> avg_pool_1d(x)